placing ad code within javascript if() conditional. does it look OK?

Discussion in 'Guidelines / Compliance' started by Oreamnos, Feb 1, 2006.

  1. #1
    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
     
    Oreamnos, Feb 1, 2006 IP
  2. BuildHome

    BuildHome Well-Known Member

    Messages:
    837
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Your if statement isn't good. Your code won't work well.
    If you'll fix it can work for you..
     
    BuildHome, Feb 1, 2006 IP
  3. Oreamnos

    Oreamnos Well-Known Member

    Messages:
    154
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    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?
     
    Oreamnos, Feb 1, 2006 IP
  4. BuildHome

    BuildHome Well-Known Member

    Messages:
    837
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #4
    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".
     
    BuildHome, Feb 1, 2006 IP
  5. kalashnik0v

    kalashnik0v Peon

    Messages:
    57
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There is one major problem - the TOS does not allow you to alter Adsense code in any way, so be careful :)
     
    kalashnik0v, Feb 1, 2006 IP
  6. AdsenseAddict

    AdsenseAddict Peon

    Messages:
    826
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    0
    #6
    tsk tsk. better change that code the way it used to be or G will karate you.
     
    AdsenseAddict, Feb 1, 2006 IP