I am trying to prevent ads from being shown to users outside of the US. So i got a little snippet of code from GeoBytes to create a simple Javascript if statement. Then i inserted my google code into the if conditional. it looks like this: <html> <head> </head> <body> <script language="Javascript" src="http://gd.geobytes.com/Gd?pages=US&ext=html&after=-1"></script> <script language="javascript"> if(typeof(sGeobytesLocationCode)!="undefined"&&sGeobytesLocationCode.indexOf('US')==0) { document.write("<script type=\"text/javascript\">"); google_ad_client = "pub-0345722508246714"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text_image"; google_ad_channel =""; document.write("<\/script>"); document.write("<script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"><\/script>"); } else { document.write("hi"); } </script> </body> </html> PHP: it does actually work, at least it shows the ad to US users and "hi" to non-US users. my question, do you see any problems with this code? do you think i will still get credit for the clicks if things are set up this way? frankly, i need to do this for YPN ads, not google. im just posting the adsense here as an example. eric
buildhome, i didn't actually write the if() conditional, i just put the ad code between the conditional {} brackets. so what do you see wrong with the if conditional? how would you make it better?
I don't see where did you config "sGeobytesLocationCode" and the "indexOf" isn't right..It's need to be "indexOf(string)" when "string" is something that you want to search in "sGeobytesLocationCode".
There is one major problem - the TOS does not allow you to alter Adsense code in any way, so be careful