Putting ads on my site

I got a letter from Google today with the pin used to verify my address (it took about a month to arrive) for the Google AdSense program (I had previously had ads on the earlier version of the AMXL, but Google started sending public service advertisements only because it had been too long without the address being confirmed).

This raises questions about whether I should have adverts on this site. This site is not intended to be a profit-making endeavour, and putting on Google ads also means that Google can track people. On the other hand, if it gets linked to from a high-traffic site, it would be good to recoup the bandwidth costs.

As a compromise, I have made it so it is easy for people who don't want to see ads to turn them off completely. In this article I discuss how I did this using Drupal.

Drupal makes it very easy to create blocks of content from within the administrative interface without going through any of the messy uploads.

I first had to create an 'Input format' type, which I called 'Unchanged', which didn't change the code at all before outputting it. I did this by following the Site configuration link from the Drupal 6.8 administration area, and then following the "Input formats" link. I could then choose "Add Input Format", type in the name, and uncheck the boxes for all the filters.

Next, I created a new block. I put the following code (the first part is from Google AdSense's ad creation page, and the "No ads please" link was added by me. It works by setting a cookie "NoGoogleAds=YesPlease" which expires well in the future against the site.

<div style="align:center"><script type="text/javascript"><!--
google_ad_client = "pub-4345788974263690";google_ad_slot = "6531667564";google_ad_width = 728; google_ad_height = 90; //--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<a href="javascript:document.cookie='NoGoogleAds=YesPlease; expires=Sun Jan 1 00:00:00 NZDT 2040; path=/';window.location.reload()">No ads please</a>

Next, I needed to make it so this cookie would actually turn off ads. Under page visibility settings, I chose "Show if the following PHP code returns TRUE", and put in the following PHP code:

if ($_COOKIE['NoGoogleAds'] == false)
return TRUE;
return FALSE;

Finally, after creating the block, I had to drag it to the header section from the Blocks configuration page, and save my block configuration. Testing indicates that things now seem to work.

Note that cookies are saved on users' computers, and not against their account. I also allowed users to opt-out from seeing the ads through their user page when I set up the block if this is desired (this is only useful for users who have created themselves an account on my site).