Skip to main content

Drupal, AdSense, and performance measuring through URL channel tracking

Posted in

Seems like I allowed my AdSense account to grow into a mess over the last year. After experimenting with banner placement and different ad units, click tracking became nearly impossible. So, time to clean it up a bit.

The thing, I am interested in most, at the moment, is figuring out whether certain (blog) topics produce more revenue than others. Or more precisely: which pages are my biggest money makers. In theory this should be easy. All I need to do is to tell Google to track individual pages via custom URL channels. In practice, however, the problem lies with compiling the URL list. Luckily, the views module is ideal for squeezing that kind of information out of the database.

Here's the view definition, I came up with for this task (see below for usage instructions):

$view = new view;
 
$view->name = 'popular_adsense';
 
$view->description = '';
 
$view->tag = '';
 
$view->view_php = '';
 
$view->base_table = 'node';
 
$view->is_cacheable = FALSE;
 
$view->api_version = 2;
 
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
 
$handler = $view->new_display('default', 'Defaults', 'default');
 
$handler->override_option('fields', array(
 
  'path' => array(
 
    'label' => '',
 
    'alter' => array(
 
      'alter_text' => 0,
 
      'text' => '',
 
      'make_link' => 0,
 
      'path' => '',
 
      'link_class' => '',
 
      'alt' => '',
 
      'prefix' => '',
 
      'suffix' => '',
 
      'target' => '',
 
      'help' => '',
 
      'trim' => 0,
 
      'max_length' => '',
 
      'word_boundary' => 1,
 
      'ellipsis' => 1,
 
      'html' => 0,
 
      'strip_tags' => 0,
 
    ),
 
    'empty' => '',
 
    'hide_empty' => 0,
 
    'empty_zero' => 0,
 
    'absolute' => 1,
 
    'exclude' => 0,
 
    'id' => 'path',
 
    'table' => 'node',
 
    'field' => 'path',
 
    'relationship' => 'none',
 
  ),
 
));
 
$handler->override_option('sorts', array(
 
  'totalcount' => array(
 
    'order' => 'DESC',
 
    'id' => 'totalcount',
 
    'table' => 'node_counter',
 
    'field' => 'totalcount',
 
    'relationship' => 'none',
 
  ),
 
));
 
$handler->override_option('filters', array(
 
  'status' => array(
 
    'operator' => '=',
 
    'value' => '1',
 
    'group' => '0',
 
    'exposed' => FALSE,
 
    'expose' => array(
 
      'operator' => FALSE,
 
      'label' => '',
 
    ),
 
    'id' => 'status',
 
    'table' => 'node',
 
    'field' => 'status',
 
    'relationship' => 'none',
 
  ),
 
  'totalcount' => array(
 
    'operator' => '>',
 
    'value' => array(
 
      'value' => '0',
 
      'min' => '',
 
      'max' => '',
 
    ),
 
    'group' => '0',
 
    'exposed' => FALSE,
 
    'expose' => array(
 
      'operator' => FALSE,
 
      'label' => '',
 
    ),
 
    'id' => 'totalcount',
 
    'table' => 'node_counter',
 
    'field' => 'totalcount',
 
    'relationship' => 'none',
 
  ),
 
));
 
$handler->override_option('access', array(
 
  'type' => 'perm',
 
  'perm' => 'access statistics',
 
));
 
$handler->override_option('cache', array(
 
  'type' => 'none',
 
));
 
$handler->override_option('title', 'AdSense URL channel list');
 
$handler->override_option('items_per_page', 150);
 
$handler->override_option('style_options', array(
 
  'grouping' => '',
 
));
 
$handler = $view->new_display('page', 'Page', 'page_1');
 
$handler->override_option('path', 'popular/adsense');
 
$handler->override_option('menu', array(
 
  'type' => 'none',
 
  'title' => 'AdSense URL channel list',
 
  'description' => '',
 
  'weight' => '0',
 
  'name' => 'navigation',
 
));
 
$handler->override_option('tab_options', array(
 
  'type' => 'none',
 
  'title' => '',
 
  'description' => '',
 
  'weight' => 0,
 
  'name' => 'navigation',
 
));

You can import this definition by using copy&paste. Just go to admin/build/views/import. After doing so, keep the following things in mind:

  • The URL path of the view is popular/adsense and can only be accessed by users, having the "access statistics" permission.
  • The view will produce a list of URLs, suitable to import into AdSense via copy&paste. This list is limited to your top 150 pages (since Google only allows 200 channels in total and you might want to reserve some as "custom channels"). Popularity is based on total node count. That is, you must enable "Count content views" in the access logs settings (admin/reports/settings).
  • Since Drupal only counts access to nodes, the list will also only contain node URL's. If you have advertisement on lists pages (e.g. taxonomy lists or views), you'll have to manually add these URLs to your AdSense tracking.
  • For best results, install the browscap module and clear your node counter a couple of days before using my view definition. This way, you make sure that only pages get tracked, which are actively being read.