/    Sign up×
Community /Pin to ProfileBookmark

Conditional display of AdSense Code

I have a forum which displays AdSense ads to non-registered users but not to registered users.

In my html pages I inserted a conditional statement at the top of my AdSense publisher code like this:

<script type=”text/javascript”><!–
if (asppg_showGoogleAds){
google_ad_client = “pub-xxxxxxxxxxxxxxxx”;
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = “728x90_as”;
google_ad_type = “text”;
google_ad_channel =””;
google_color_border = “80FFFF”;
google_color_bg = “80FFFF”;
google_color_link = “0080C0”;
google_color_text = “000000”;
google_color_url = “000000”;
}
//–></script>
<script type=”text/javascript” src=”http://pagead2.googlesyndication.com/pagead/show_ads.js“>
</script>

This has worked fine for a long time but I have now been told by Google that it is against their Terms and Conditions to modify the publisher code in this way.

I am sorry to say that because of my ignorance of javascript I have no idea how I might move the conditional statement outside the publisher code and still have it work as intended.

Any help much appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliOct 12.2007 — I have a forum which displays AdSense ads to non-registered users but not to registered users.

In my html pages I inserted a conditional statement at the top of my AdSense publisher code like this:

<script type="text/javascript"><!--

if (asppg_showGoogleAds){

This has worked fine for a long time but I have now been told by Google that it is against their Terms and Conditions to modify the publisher code in this way.
[/quote]

You could import that section selectively from an external file, that way nobody can say it's been touched.

Untested:
&lt;script type="text/javascript"&gt;
if (asppg_showGoogleAds &amp;&amp; document.createElement)
{
var gAds=document.createElement('script');
gAds.src='googleads.js';
document.body.appendChild(gAds);
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@SparrowhawkauthorOct 12.2007 — Thank you Logic Ali

I tried it and it works only when Adsense Ads should not be displayed.

When AdSense Ads should be displayed it causes IE7 to have a fatal error and cannot display the page.

This means I cannot view source and see what's there.
×

Success!

Help @Sparrowhawk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...