Home |
Blog |
( 2 ) |
Subscribe
Disclosure: This post may contain affiliate links which may earn us a commission when you click on them.
Posted by
Felix Okoli on Saturday January 15, 2011 at 10:38:57:
Although I already have been using external .js files to refer to my Google adsense format, I was still using one src component from within my web pages to refer to the adsense server. I had been thinking for a long time if there was any way I could also use an external file to point to the src values without using it from my main pages so that in case I want to switch over to another advertising platform in the near future, test for a day or just want to edit those .js scripts, I would not have to be editing them page by page even if it means using dreamweaver to edit thousands of pages at one using search and replace. Currently, here is the form I use in embedding the adsense code on my page using an external .js file:
script type = text/javascript src= http://www.multidox.org/format.js script
script type = text/javascript src= http://pagead2.googlesyndication.com/pagead/show_ads.js script
format.js:The first src points to a .js file within my website and it is just the ad format which contains pure javascript in the form:
google_ad_client = pub-1051693710473243
/* Format */
google_ad_slot = 1737332916
google_ad_width = 728
google_ad_height = 15
However I still wanted to be able to just include only just one src that will reference every other item so that if I just want to change everything about that ad within my site, I would only have to just edit that .js file without going back to my website. For instance, if I wanted to test how much Adbrite will make for me on my site for a 24 hr period, I would just have to edit a single .js file without going back to remove the google links or edit my web pages. So I had been Googling for it for several months and later forgot about it until yesterday when I somehow ran into it. The simple solution relied on just a simple javascript code for using srcs - document.write.
So here is what I just have to embed on my website html code and it works. I created a pure .js file and put in the following codes:
pure.jsdocument.write(script src=http://www.multidox.org/format.js type= text/javascript /scriptdocument.write(script src= http://pagead2.googlesyndication.com/pagead/show_ads.js type= text/javascript script
So this actually works better on my site such that IF I want to test for another ad and how much it could pay me per day, I would just edit the pure.js file by including src values for javascript files located on my web server.
So in order to do the above, all I needed was 2 javascript files:
- pure.js and format.js
pure.js contains the document.write src values for file locations - one on my server(format.js) and the other on google server(http://pagead2.googlesyndication.com/pagead/show_ads.js)
Testing with Adbrite or other ad network:
To do this all I would need is to edit the pure.js file and just include the adbrite code in the form:
document.write(script src=
http://ads.adbrite.com/mb/text_group.php?sid=123&br=1&dk=123 type=text/javascript /script)
Comments:
Re: Using external .js files for Google adsense code
Posted by Wilson
on Thursday January 27, 2011 at 15:55:15:
The first method i think is acceptable to Google but i don't know about the second one. That code ought to be pasted on the actual page and not in a javascript file. I mean the "http://pagead2.googlesyndication.com/pagead/show_ads.js" since it appears that Google spiders would read your page from your referring url and if they find out that it was pasted on a javascript code, it may go against their TOS. Why not ask Google first?