Drupal 5: Add Google Lead Conversion Tracking to registration page

Submitted by Janak on Wed, 09/09/2009 - 12:56

Ever wanted to alter the the registration page in Drupal 5 to add your own bit of custom code or text? For most of the work websites, we use adwords to bring in traffic and as with any campaign, you would want to monitor the success rate etc.

We needed to add a bit of Google lead conversion tracking code (javascript+html) on the website registration page.

As you might already know, there are multiple ways of doing this:

Add Custom Text to Drupal 5 Registration Page:

However, I wanted to try to keep my implementation confined to just a single module and not have to implement code in multiple places (template files etc). So, after a little bit of poking around in the Drupal API, I found this handy function called "drupal_set_content"...

Here is how to implement this in your own module to add tracking to virtually any page:

function mymodule_init(){
  $arg0 = arg(0);
  $arg1 = arg(1);
  $arg2 = arg(2);
 
  if($arg0 == "user" and $arg1 == "register" and !isset($arg2)){
 
    $google_conversion = '
    <!-- Google Code for Lead Conversion Page --> 
    ....
    ....
    ....
    ....    
    ';    
 
    drupal_set_content('footer', $google_conversion);
  }
  //elseif($arg0 == "user" and $arg1 == "register" and $arg2 == "welcome"){
  //if you want to do more
  //}
 
}

For drupal 6 we have been gifted with hook_preprocess_page funtion and will not need o do most of this..