Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How do I rotate Google ads?
Old 07-25-2007, 04:46 PM How do I rotate Google ads?
Angelosanto's Avatar
Webmaster Talker

Posts: 548
Name: Danny Angelosanto
Trades: 0
Well its pretty much all in the title - I tried generating a variable with the value of a random number between 0 and 1, and then using IF (the variable) is equal to or more than 0.5, display (first ad), ELSE (second ad)

This didn't work.

I just want to have my ads showing 50% of the time, and someone elses ads showing 50% of the time - how?

Thanks in advance
__________________
"The only reason some people get lost in thought is because it's unfamiliar territory."
_____________________________________
Angelosanto is offline
Reply With Quote
View Public Profile Visit Angelosanto's homepage!
 
 
Register now for full access!
Old 07-25-2007, 06:32 PM Re: How do I rotate Google ads?
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Danny I think I would have tried it the same way you did. Do you want to post the code?
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-26-2007, 12:05 AM Re: How do I rotate Google ads?
VTWebProperties's Avatar
Skilled Talker

Latest Blog Post:
WEB 2.0 Apps For iPhone
Posts: 64
Name: Ed
Location: Vermont
Trades: 0
Any chance you can use a server-side rotator? This way you can also expand to add a third, fourth or ... number of options in rotation and manage it without having to change code later.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
VTWebProperties is offline
Reply With Quote
View Public Profile Visit VTWebProperties's homepage!
 
Old 07-26-2007, 12:35 AM Re: How do I rotate Google ads?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I use integers and find it works better (in your case, 1 and 2).

www.libreriapandevida.com (the ad rotator on the top right...steal the code and modify to your heart's content.)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 07-26-2007, 04:29 PM Re: How do I rotate Google ads?
Angelosanto's Avatar
Webmaster Talker

Posts: 548
Name: Danny Angelosanto
Trades: 0
Thanks for the help guys - particularly ADAM
__________________
"The only reason some people get lost in thought is because it's unfamiliar territory."
_____________________________________
Angelosanto is offline
Reply With Quote
View Public Profile Visit Angelosanto's homepage!
 
Old 07-26-2007, 05:31 PM Re: How do I rotate Google ads?
Angelosanto's Avatar
Webmaster Talker

Posts: 548
Name: Danny Angelosanto
Trades: 0
Sorry, but I realised that I actually dont get it after all lol

sorry to bother you again, but 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 )

HTML Code:
<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>
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:

HTML Code:
 if (r>0.5) 

    {
var pubID = ***My Publisher ID***
    }

else

    {
var pubID = ***My Partners Publisher ID***
    }
Again - no luck.

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

Thanks very much
__________________
"The only reason some people get lost in thought is because it's unfamiliar territory."
_____________________________________
Angelosanto is offline
Reply With Quote
View Public Profile Visit Angelosanto's homepage!
 
Old 07-27-2007, 09:48 AM Re: How do I rotate Google ads?
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
Trades: 0
....... ok this is the way I would do it myself...

Wrap the google script inside a <div> tag with an id, then create a timer so that every lets say 5 mins it would then rewrite the innerHTML of that divider.

Of course I am unsure if it would work as I havn't tried it myself.

Also you should use whole numbers, so when you use the math.random() ability it will generate a whole number
__________________
Matthew Bagley
Paramiliar Design Studios

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Paramiliar is offline
Reply With Quote
View Public Profile
 
Old 07-27-2007, 01:10 PM Re: How do I rotate Google ads?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Paramillar has the right idea...your major problem is that you're trying to include Javascript within Javascript. This can work, but you should be putting it in some sort of quotes or something along these lines:
Code:
var googleAd1 = '<script type="text/javascript"><!--\n';
googleAd1 += 'google_ad_client = "pub-8905391473999593";\n';
...
Paramillar: the problem with your method is that you'd have to hide the divs on the page, which means the ad code would load (as would ads) but they wouldn't show initially. This would be a violation of Google's ToS. Not a bad thought, though.


Angelosanto: if you wanted to try something along the lines of what Paramillar suggested, you could create a page containing nothing but the Google Adsense code and have it retrieved via AJAX. That's another option.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 07-28-2007, 07:02 PM Re: How do I rotate Google ads?
Angelosanto's Avatar
Webmaster Talker

Posts: 548
Name: Danny Angelosanto
Trades: 0
Thanks very much - I think I managed to figure out how to work it

Thats the good news. The bad news is, that most people I've spoken to seem to be of the opinion that it counts as violating adsense ToS.

Sooooo, after all that, I'm afraid I'm going to have to move this query over to the PHP section!

Sorry about that guys, and thanks for your support!
__________________
"The only reason some people get lost in thought is because it's unfamiliar territory."
_____________________________________
Angelosanto is offline
Reply With Quote
View Public Profile Visit Angelosanto's homepage!
 
Old 07-28-2007, 09:10 PM Re: How do I rotate Google ads?
Experienced Talker

Latest Blog Post:
Long time no … erm post?
Posts: 45
Name: Matthew Bagley
Trades: 0
Quote:
Originally Posted by Angelosanto View Post
Thanks very much - I think I managed to figure out how to work it

Thats the good news. The bad news is, that most people I've spoken to seem to be of the opinion that it counts as violating adsense ToS.

Sooooo, after all that, I'm afraid I'm going to have to move this query over to the PHP section!

Sorry about that guys, and thanks for your support!
forgive any tytpos as am highly dfrunk but php wouldf be a simplke case of getting it to outpue the code based on arandom number found
__________________
Matthew Bagley
Paramiliar Design Studios

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Paramiliar is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How do I rotate Google ads?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31213 seconds with 12 queries