1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Rotating Ads with JS

Discussion in 'AdSense' started by Loplin, Apr 19, 2005.

  1. #1
    I have recently added AdSense Adlinks to a website I host.

    In order to see which combination of colors/ad types would be most profitable, I wanted to make a script that would automatically rotate one adblock between the following...

    1)AdLink Block with colors that match the site
    2)Adlink Block with colors that Stand Out
    3)AdSense Button block with colors that match the site
    4)AdSense button block with colors that stand out.

    I was going to make a channel for each and have the script randomly serve one of these 4. At the end of the month, which ever ad type made the most money was going to get that spot.

    Why not use php? The server I host on is not what you might call High End and the scripts that I run are server intensive. As a result, I use a squid proxy to caching. This way a page is only generated once, until it is updated, then cached and served from memory, which means a php randomizer wouldn't work.

    I tried to do something like this....


    
    
    <script language="JavaScript" type="text/javascript">
    var whichad = 0;
    var currentdate = 0;
    
    currentdate = new Date();
    whichad = currentdate.getTime();
    whichad = (whichad/10) % 3;
    
    
    if (whichad==1) {
    document.write('
                 <script type="text/javascript"><!--
                   google_ad_client = "xxxxxxxxxxxxxxxxxxxxxx";
                   google_ad_width = 120;
                   google_ad_height = 90;
                   google_ad_format = "120x90_0ads_al_s";
                   google_ad_channel ="7187255059";
                   google_color_border = "FFFFFF";
                   google_color_bg = "FFFFFF";
                   google_color_link = "000000";
                   google_color_url = "3333FF";
                   google_color_text = "000000";
                   //--></script>
                   <script type="text/javascript"
                   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>');
    } else {
    document.write('<script type="text/javascript"><!--
    		google_ad_client = "pub-xxxxxxxxxxxxxxxx";
    		google_ad_width = 125;
    		google_ad_height = 125;
    		google_ad_format = "125x125_as";
    		google_ad_type = "text";
    		google_ad_channel ="1135773472";
    		google_color_border = "FFFFFF";
    		google_color_bg = "FFFFFF";
    		google_color_link = "000000";
    		google_color_url = "3333FF";
    		google_color_text = "000000";
    		//--></script>
    		<script type="text/javascript"
      		src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    		</script>');
    
    }
    </script>
    
    Code (markup):

    This would work great, the AdSense code IS put in without modification: Problem... the "< /script >" in the AdSense code stops the script prematurely and ends up writing the rest of the script to the page, not executing it.

    Would anyone know of a way around this without violating the TOS?

    Thank you
     
    Loplin, Apr 19, 2005 IP
  2. fryman

    fryman Kiss my rep

    Messages:
    9,604
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    370
    #2
    There is an option to use up to 3 color combinations when you create your code in yourt account, check it out, very cool feature.

    But I don't think you'll be able to track each combination, it is just for rotating colors.
     
    fryman, Apr 19, 2005 IP
  3. NewComputer

    NewComputer Well-Known Member

    Messages:
    2,021
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    188
    #3
    According to many, with what you wrote above, you already have violated their TOS...

     
    NewComputer, Apr 19, 2005 IP
  4. Loplin

    Loplin Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yeah, I knew about the color rotating, but I wanted them to be completely seperate so I could track them seperatly. At least in the beginning.

    Thanks though.

    BTW: The code above is only for 2 of the 4 ads.
     
    Loplin, Apr 19, 2005 IP
  5. pchere

    pchere Peon

    Messages:
    119
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Rotating ads like that will violate TOS. Why not use channels instead to see which works best.
     
    pchere, Apr 21, 2005 IP
  6. bnaze13

    bnaze13 Peon

    Messages:
    62
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think I would use php over javascript for something like this. The rand() function works nicely for things like that.
     
    bnaze13, Apr 21, 2005 IP
  7. wendydettmer

    wendydettmer Peon

    Messages:
    1,462
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Channels is the way to go in this case. Roatating the ads could get you in trouble with google.
     
    wendydettmer, Apr 21, 2005 IP
  8. Loplin

    Loplin Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    pchere
    I don't mean to rotate ads in the middle of a page view, I mean, each refresh should display a different type of ad, be it a Button ad or AdLinks ad. This is basicly the same changing the colors between page views, which is what php scripts have done already. I'm not sure why this would be against TOS, but, please point me to where it is. I definately do not want to violate the rules.

    bnaze13
    I can't use php because the server I host on is not what you might call High End and the php scripts that I DO run are server intensive. As a result, I use a squid proxy to caching. This way a page is only generated once, until it is updated, then cached and served from memory, which means a php randomizer wouldn't work every reload.


    Why not use channels to see which would work best?


    This is what I -want- to do. I want to set each different ad type on a different channel to see which would do best. But, instead of displaying one for a week, then another for a week, and another for another week, etc, which could take months; instead, I want to make a random type of ad appear on each page load so that this four week process can be cut down to one or two weeks.

    So if I had an adlink block appear the first time I see the page, when I hit reload, it might be a AdButton the next time. I currently do not see a built in way to do this with the ad creator page. There is a way to rotate colors built in, but unfortunatly, you can't track each color seperatly, which is something else I would like to do.


    Thanks for all of your input, I am currently exploring other ways of doing this.
    /Loplin
     
    Loplin, Apr 21, 2005 IP
  9. Loplin

    Loplin Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Perhaps 'rotating' was the wrong word to use. 'Randomizing' would have been more appropriate. I would change the title of the topic if it hadn't been more than 480 minutes already ;)

    /Loplin
     
    Loplin, Apr 21, 2005 IP
  10. aenigma

    aenigma Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Use this:
    
    
    document.write('<sc' + 'ript type="text/javascript"> ...... etc.
    
    
    Code (markup):
     
    aenigma, Apr 22, 2005 IP