How do I rotate Google ads?

Discussion in 'JavaScript' started by Angelosanto, Jul 26, 2007.

  1. #1
    Well its pretty much all in the title - I just want to have my ads showing 50% of the time, and someone elses ads showing 50% of the time - how?

    I don't understand why this isn't working. My first thought was to try this:

    (By the way, I'm really a bit clueless when it comes to JavaScript, so bear with me!)

    <script type="text/javascript">
    
    var r=Math.random()
    
    if (r>0.5) 
    
        {
    
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-1472271703469017";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text_image";
    google_ad_channel = "";
    google_color_border = "FFFFCC";
    google_color_bg = "FFFFCC";
    google_color_link = "6F3C1B";
    google_color_text = "6F3C1B";
    google_color_url = "6F3C1B";
    //-->
    </script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
        }
    
    else
    
        {
    
    <script type="text/javascript"><!--
    google_ad_client = "pub-8905391473999593";
    google_ad_width = 160;
    google_ad_height = 600;
    google_ad_format = "160x600_as";
    google_ad_type = "text_image";
    google_ad_channel = "";
    google_color_border = "FFFFCC";
    google_color_bg = "FFFFCC";
    google_color_link = "6F3C1B";
    google_color_text = "6F3C1B";
    google_color_url = "6F3C1B";
    //-->
    </script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    
        }
    
    </script>
    HTML:
    I did spot several possible flaws in this, including the inclusion of the script tags and the (")'s that should perhaps have been (')'s, but no matter which variation I use, I cant suss it.

    Then I tried to change the publisher ID to a variable, and use:

    if (r>0.5) 
    
        {
    var pubID = ***My Publisher ID***
        }
    
    else
    
        {
    var pubID = ***My Partners Publisher ID***
        }
    HTML:
    Again - no luck.

    So please - I am tearing my hair out over this one - does anybody have the solution?

    Thanks very much
     
    Angelosanto, Jul 26, 2007 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    You'd better use server side scripting,

    I'm telling you to do that because IMO you can't do that with JavaScript without modifying the AdSense code (not allowed)

    BTW: Nesting javascript doesn't work
     
    nabil_kadimi, Jul 27, 2007 IP
  3. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Indeed; use server side scripting. All revenue sharing solutions are using server side scripting like ASP or PHP. :)
     
    DeViAnThans3, Jul 28, 2007 IP
  4. Angelosanto

    Angelosanto Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK, thanks guys. Guess I'll move this to the PHP forum then :D
     
    Angelosanto, Jul 28, 2007 IP
  5. BigMumu

    BigMumu Peon

    Messages:
    159
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    BigMumu, Aug 24, 2007 IP