homepage Welcome to WebmasterWorld Guest from 54.242.200.172
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Google / Google AdSense
Forum Library, Charter, Moderators: incrediBILL & jatar k & martinibuster

Google AdSense Forum

    
How insert ads based on JavaScript variable?
Taffa




msg:1317606
 3:18 pm on Apr 21, 2006 (gmt 0)

I want load ads only when custom JavaScript variable is set to true.

if true...
google_ad_client = "---";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "9DADC6";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";

var x = document.createElement("script");
x.src = "http://pagead2.googlesyndication.com/pagead/show_ads.js";
document.body.appendChild(x);

Although script element is added to DOM browsers don't show nothing. Any suggestions?

 

greatstart




msg:1317607
 4:03 pm on Apr 21, 2006 (gmt 0)

That violates the TOS. You are modifing the code!

celgins




msg:1317608
 4:07 pm on Apr 21, 2006 (gmt 0)

Taffa... I'm not exactly sure what you're trying to do, but you can load different Adsense code based on whatever variable you want. For example, you can load different Adsense codes based on whether a user is using Firefox or IE; or whether or not a CSS screen background is white or black; or whatever.

However, you are not allowed to change the Adsense code itself. That is against the TOS.

jomaxx




msg:1317609
 4:08 pm on Apr 21, 2006 (gmt 0)

You are not allowed to change the code. You have to do this server-side, via PHP or SSI for example. If you need to have a JS component, you can put the flag into a cookie.

inbound




msg:1317610
 4:14 pm on Apr 21, 2006 (gmt 0)

A simple solution would be to use php (or something similar) to decide whether to have the script sent to the browser. That way there is no need to risk being penalised.

e.g.

if ( $your_boolean_variable == true) {
echo $AdSense_code_in_this_string;
}

You could expend the code to add whatever you like or even add an ELSE clause that uses alternative code to fill the space that AdSense would have taken up.

Taffa




msg:1317611
 4:28 pm on Apr 21, 2006 (gmt 0)


That violates the TOS. You are modifing the code!

I have understood that this not code modifying. I even remember that there was official answer somewhere that it doesn't matter how the JavaScript sections are added to the page as long as the actual adsense code written to the page is not modified. You can even use external .js for parameter part.

Can't use server side stuff, need to detect plug-in and if it is not present display also ads (there is lot of empty space in this case) This is mainly for IE users who are reluctant to install plug-in I'm currently using.

<!--[if IE]>
adsense code here
<![endif]-->

jomaxx




msg:1317612
 6:09 pm on Apr 21, 2006 (gmt 0)

IMO the requirement is to take the code generated by Google and paste it into your page unchanged. In your case the end result may appear the same once the JS is executed (if you can get it to work), but the code has clearly been changed.

Using something like PHP to write out the code conditionally is OK because the end result is indistinguishable from cut-and-pasted code to any browser or spider.

milanmk




msg:1317613
 6:54 pm on Apr 21, 2006 (gmt 0)

How about this one:

if (var == true)
{
google_ad_client = "---";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="";
google_color_border = "9DADC6";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_url = "008000";
google_color_text = "000000";
}
<script src="googlesyndication js file"></script>

I dont know whether its against TOS or not.

Milan

MyGen




msg:1317614
 7:32 pm on Apr 21, 2006 (gmt 0)

Setting a simply ifelse statement is not against the TOS,


<script type="text/javascript">
if (var==true) {
ADSENSE CODE HERE;
} else { whatever you want to appear if var is false }
</script>

Obviously it would be easier to do using a serverside technology, as has already been shown.

jomaxx




msg:1317615
 8:26 pm on Apr 21, 2006 (gmt 0)

"code must be pasted directly into Web pages without modification"

How hard is this statement to understand?

Taffa




msg:1317616
 8:36 pm on Apr 21, 2006 (gmt 0)

I checked how it was done and it was different.
Whole adsense code was put inside google.js

<!--
google_ad_client = "---";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
//-->

and then was called with
<script type="text/javascript" src="google.js"></script>
(If I choose to use this method I would write this part with javascript)

Apparently this only works with IE, but thas enough.
At least [webmasterworld.com...]
says:

Its acceptable.

An email from their support.

Thank you for your email. Placing the AdSense code within a .js file is acceptable so long as there is no alteration of the AdSense code itself.

We realize that this makes the AdSense code much easier to maintain across an entire website.

App is coded with PHP so I can try Cookie approach.
Just need to figure out what to do with first time users. Maybe it is best to shows ads by default and stop only when cookie states that plug-in is installed.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Google / Google AdSense
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved