Drupal 7 module: Google Analytics

Google Analytics module for Drupal 7 is available here: http://drupal.org/project/google_analytics. This module adds the Google Analytics web statistics tracking system to your website.

The module allows you to add the following statistics features:
- Single/multi/cross domain tracking
- Selectively track/exclude certain users, roles and pages
- Monitor what type of links are tracked (downloads, outgoing and mailto)
- Monitor what files are downloaded from your pages
- Custom variables support with tokens
- Custom code snippets
- Site Search support
- AdSense support
- Tracking of Goals
- Anonymize visitors IP address
- Cache the Google Analytics code on your local server for improved page loading times
- Access denied (403) and Page not found (404) tracking
- DoNotTrack support (non-cached content only)

In April 2011 there is 7.x.-1.2 version available, which I'm going to install. First step is to download SRC zip package and extract it into /sites/all/modules directory of my Drupal 7 site. After SRC is in place I just simple enable module in modules administration screen.

When Google Analytics module is enabled for Drupal 7 it needs to be configured after. You need to log in to your Google Analytics account http://www.google.com/analytics/ where you can obtain your tracking ID. If you are not familiar with GA, please see attached images how to do that. When you obtain your Web Property ID you can simple configure Drupal module.

At this point I have only filled out Web Property ID for Drupal module and left all other options as default. There is a lot of interesting options for this D7 module but default values are good for me at this time. I might come back later and review other options.

To make sure your module works properly you should be able to view source code of your page (homepage for example) and see tracking code in there. Something like following lines:

var _gaq = _gaq || [];_gaq.push(["_setAccount", "UA-1325063-22"]);_gaq.push(["_trackPageview"]);(function() {var ga = document.createElement("script");ga.type = "text/javascript";ga.async = true;ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";var s = document.getElementsByTagName("script")[0];s.parentNode.insertBefore(ga, s);})();

Blog Image: