Welcome to WebmasterWorld Guest from 54.145.166.96

Forum Moderators: incrediBILL & martinibuster

Message Too Old, No Replies

Running AdSense Code With External JavaScript File?

   
7:57 am on Nov 11, 2003 (gmt 0)

10+ Year Member



Howdy,

Have been on AdSense for just over a week now and things are going fairly well, but I just received an email from Google telling me I've modified the code and suggested that I review their Program Policies.

I have my code set up as follows:

Displayed in the html:
<script type="text/javascript" src="/js/google.js"></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

And in the /js/google.js file:
<!--
google_ad_client = "XXX";
google_alternate_ad_url = "http://www.XXX.com/gfx/sp.gif";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_color_border = "B4D0DC";
google_color_bg = "ECF8FF";
google_color_link = "0000CC";
google_color_url = "008000";
google_color_text = "6F6F6F";
//-->

I read in an earlier thread (which I can't seem to find right now) that we were allowed to run the code in external js files, but now I'm not so sure.

Ideas?

8:28 am on Nov 11, 2003 (gmt 0)

WebmasterWorld Senior Member jenstar is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Here is the thread you are remembering [webmasterworld.com]

The difference is that you are splitting the AdSense code between your page and the js, and you are not permitted to alter the code in any way at all. The "http://pagead2.googlesyndication.com/pagead/show_ads.js" has to be together with the rest of the AdSense code.

The link above shows you how to do it correctly, which is Google approved, or at least approved as of a month ago.

10:03 am on Nov 11, 2003 (gmt 0)

10+ Year Member



hmmm.. ok I removed the <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> reference from the html file and added it to the bottom of my /js/google.js file, but am receiving an error. Based on the link Jenstar provided (thanks!) Here's the revised code I'm trying to use in the /js/google.js file:

<!--
google_ad_client = "XXX";
google_alternate_ad_url = "http://www.XXX.com/gfx/sp/gif";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_color_border = "B4D0DC";
google_color_bg = "ECF8FF";
google_color_link = "0000CC";
google_color_url = "008000";
google_color_text = "6F6F6F";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
//-->

I've tried numerous combinations, even the exact code provided in the other thread, and I consistently get an error on line 13 (src="http://...) and the banners do not display. It looks like javascript doesn't like it when I call another javascript file from within a javascript file because when I return the code to it's previous state (noted in the first post in this thread) there are no errors and the ads are served correctly.

Thoughts? =)

10:35 am on Nov 11, 2003 (gmt 0)

10+ Year Member



If it is any help I too tried and tried with the code on the earlier thread and could not get it to work....

If anyone comes up with how to do it. It would make a great addition to the Adsense FAQ's thread

8:16 am on Nov 12, 2003 (gmt 0)

10+ Year Member



Sort of glad it's not just me :)

My site's built in straight html and rank well in the engines so I really don't want to have to change my file extensions or structure too much in order to get an include to work for these ads.

I've also found that if I change the colour scheme every once in a while it gives me a little boost in CTR, so it's be great to find a javascript solution that remains within Google's guidelines and is easily edited.

Any ideas here would be much appreciated. :)

6:31 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Here's Javascript code that works from external JS file:

document.write("\
<script type=\"text/javascript\">\
google_ad_client = \"XXX\";\
google_alternate_ad_url = \"XXX\";\
google_ad_width = 728;\
google_ad_height = 90;\
google_ad_format = \"728x90_as\";\
</script>\
<script type=\"text/javascript\"\
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">\
</script>\
");

Andy

6:41 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member jenstar is a WebmasterWorld Top Contributor of All Time 10+ Year Member



daugava, did you run that past the Google AdSense team? They are extremely strict that they don't want their AdSense code altered whatsoever (as per the FAQ). I am pretty sure someone had said a month or two ago that doing something similar to this was vetoed by Google.
6:56 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



I guess I'd better do that, huh?

The code they provide doesn't run from external JS,
so the only change I made is making it to work.
(They have that weird mismatched /script tag which seems
to mess things up. Plus, the variables end up being
undeclared.)

I was worried about this, but then I saw the other thread
about running from external JS and I figured that whoever got it working, did exactly the same thing I did, and got approved.

Andy

7:01 pm on Nov 13, 2003 (gmt 0)

WebmasterWorld Senior Member jenstar is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You can contact the tech support team directly at adsense-tech@google.com Let us know if that script is Google approved ;)
7:49 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Ok, here's more kosher version of the code, it only differs from original just enough to make it valid Javascript:
google_ad_client = "XXX";
google_alternate_ad_url = "XXX";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
//--></script>
document.write('\
<script type="text/javascript"\
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">\
</script>\
');

I've emailed Google to ask if they approve.
If yes, we'll be able to use it, yay!

Andy

8:50 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



Dang, got a reply, which says "code cannot be altered in any way".

Therefore, it seems like an external JS will not work at all - unless the people who got approval for their version of the code post it here, so we can use that one.

Andy

9:43 pm on Nov 13, 2003 (gmt 0)

10+ Year Member



I have since changed my site back to the exact code embedded in the html.

In an email I intricately described how and why I made the edits to the code, and then asked if there was an approved method of embedding the code through an external js file. To that I recieved a stock reply thanking me for changing my code back to stock... oh well, I was probably just having a nice conversation with their mailbot the whole time. LOL :D

Oh well.

3:18 am on Nov 14, 2003 (gmt 0)

10+ Year Member



-- Owner edited because while explanatory, was actually mostly a duplicate of above. --
 

Featured Threads

Hot Threads This Week

Hot Threads This Month