homepage Welcome to WebmasterWorld Guest from 54.167.238.60
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Google / Google AdSense
Forum Library, Charter, Moderators: incrediBILL & jatar k & martinibuster

Google AdSense Forum

    
Running AdSense Code With External JavaScript File?
servoweb




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

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?

 

Jenstar




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

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.

servoweb




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

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? =)

Sense_able




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

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

servoweb




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

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. :)

daugava




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

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

Jenstar




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

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.

daugava




msg:1432428
 6:56 pm on Nov 13, 2003 (gmt 0)

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

Jenstar




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

You can contact the tech support team directly at adsense-tech@google.com Let us know if that script is Google approved ;)

daugava




msg:1432430
 7:49 pm on Nov 13, 2003 (gmt 0)

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

daugava




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

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

servoweb




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

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.

Sharper




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Google / Google AdSense
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved