Script to alternate AdSense ad types

Discussion in 'AdSense' started by minstrel, Aug 8, 2006.

  1. #1
    Source: http://adsense.blogspot.com/2006/08/abcs-of-ab-testing.html

    <script type=”text/javascript”>
        var random_number = Math.random();
        if (random_number < .5){
            //your first ad unit code goes here 
        } else { 
            //your second ad unit code goes here 
        } 
    </script> 
    <script type="text/javascript"     src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
    
    Code (markup):

     
    minstrel, Aug 8, 2006 IP
    Mystique likes this.
  2. Cryogenius

    Cryogenius Peon

    Messages:
    1,280
    Likes Received:
    118
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This can also be done with PHP, but the advantage of the JavaScript version is that you'll still get a random ad even if it's been cached, where as the PHP output will only change if it's regenerated by the server.

    Thanks minstrel - good find.
     
    Cryogenius, Aug 8, 2006 IP
    Bean likes this.
  3. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #3
    frankcow, Aug 8, 2006 IP
  4. miked

    miked Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The best part about this testing script is it's fully approved by google:

     
    miked, Aug 8, 2006 IP
  5. db4t

    db4t Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks minstreal. I'm using the script. It's working fine.
     
    db4t, Aug 8, 2006 IP
  6. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #6
    Thanks for sharing minstreal and frankcow :)

    I found while ago an ASP version but it didn't work, and obviously either in those sites hosted on Linux servers
     
    Mystique, Aug 8, 2006 IP
  7. wissam

    wissam Well-Known Member

    Messages:
    2,289
    Likes Received:
    78
    Best Answers:
    1
    Trophy Points:
    185
    #7
    Thanx, I did make one on my own before ...
     
    wissam, Aug 8, 2006 IP