Using Google AdSense Channels to track Clicks in Movable Type Categories

Published on September 6, 2004 at 2:05 PM EST
In the Tutorials category.

If you’re part of Google’s AdSense program you can set up Channels to help track where Clicks are coming from on your web site. The obvious (and easy) thing to do is assign a different Channel to your front page from the rest of your pages, for example. Using Movable Type and different categories (and even archive types) you can further target who’s clicking where. PHP use is required.

First, you’ll need to create several Channels in your AdSense account. I created Channels for the most popular categories and a “generic” channel to encompass the other less-popular categories.

Add the AdSense code to your Individual Entry Archive template. Locate the following line within the AdSense code. If it’s not there, add it.

google_ad_channel = "";

Replace that line with:

$channel_generic = '*generic channel #*';
$channel_list = array(
  '*category 1 #*' => '*category 1 name*',
  '*category 2 #*' => '*category 2 name*',);

if ($current_channel = array_search('>MTEntryCategory<', $channel_list)) {
  echo 'google_ad_channel = "' . $current_channel . '";';
} else {
  /* Generic channel for undefined categories. */
  echo 'google_ad_channel = "' . $channel_generic . '";';
} ?>

Including a generic channel seems like a good idea to me. Replace *generic channel #* with your generic channel number. Replace *category 1 #* your category 1 channel number; similar for number 2. Replace *category 1 name* with the category name you use on your web site; similar for number 2. To include more categories just add another 'channel' => 'category', combination to the list.

Once that is all in place, save the template and rebuild the individual entry archives. Verify it works through your AdSense account or by viewing the source of the rendered document and comparing channel numbers.