Drupal 5: Add Google Lead Conversion Tracking to registration page

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:

<?php
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..


Bookmark and Share

5 comments

Anonymous's picture

Could you please show some code how to do this drupal 6?

Janak's picture

Although the above code will work for D6 too, a better way would be to take advantage of the hook_preprocess_page function like this and add your output to the $variables array, for more options, see the api:

function mymodule_preprocess_page(&$variables){
  $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 -->
    ....
    ....
    ....
    ....   
    ';   
 
    //add your output to the $variables array
    $variables['footer_message'] .= $google_conversion;
  }   
}

Anonymous's picture

Which page do I paste my tracking code into, the destination url after the submit button is pressed ie thank you for your enquiry or the actual contact form page?

If it is the contact form page, how do google record the conversion, by somebody going onto the page or by somebody clicking submit enquiry?

Janak's picture

Hi,
Instead of me copy pasting from Google Adwords handbook, you might want to have a read at:
AdWords Conversion Tracking Setup Guide

and

How does AdWords Conversion Tracking code work once I've implemented it on to my pages?

If you have any questions or need Drupal implementation help, post here and I will try to help.. ;)

Anonymous's picture

This is an excellent article, thank you very much for it.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <css>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>, <vim>, <xml>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options