Drupal Statistics on Steroids

The statistics collected by Drupal‘s builtin statistics module is rather limited and there are no facilities to create nice graphs or in other ways manipulate the collected data. On the other hand there are a lot of great and free web tracker services out there which let you gather statistics on your visitors and then query that data in various ways. Today, I integrated one such service, StatCounter, with the Drupal based web site you are looking at right now.

Services like StatCounter are usually very simple to integrate into an existing web site. Typically they give you a piece of HTML code (often with some JavaScript thrown into the mix) which you then add to the pages of your site. Whenever someone visits your site this code will trigger a request to a server-side script on the web tracker service’s web site. The request usually contains data such as the visitor’s ip address, browser, operating system, the current time, etc.

StatCounter, which I stumbled across today, collects lots of data on your visitors (without sacrificing their privacy, of course). The cool thing about StatCounter which I think sets it apart from the competition is that it is completely free in the sense that it won’t cost you anything yet still you don’t have to add a link to their web site if you don’t want to and no ads will pop up in the face of your visitors. In fact, your visitors will not be able to tell (if you don’t want to and as long they don’t take a look at your site’s HTML code) that they are being tracked.

Integrating StatCounter (and any other similar service) with a Drupal web site is a piece of cake. This is how I did it (in Drupal 4.6.0):

  1. Create a new block by selecting administer -> blocks in the menu and click the add block tab. You can leave the Block title field empty. Paste the HTML code given to you by the web tracker service in the Body block text area. Make sure the Full HTML radio button is selected in the Input format section. Enter a description in the Block description field (I entered “StatCounter code”) and hit the Save block button.
  2. The new block will now be listed in the Disabled section in the list of available blocks on the blocks page (administer -> blocks). The description you used for your block will be used as the label in the list. Tick the checkbox in the Enabled column next to the web tracker block we created in 1, change its weight and placement (left or right sidebar) if necessary and hit the Save blocks button.

That’s all there is to it! The HTML code you got from the web tracker service should now be included in all the pages of your site (have a look at the source of your site’s pages to confirm this).  If you don’t want it to be used on every page you should click the configure link next to the block we created above. The block configure page shown lets you specify individual pages or content types (blogs, pages, stories, etc) on which the block should be included.

// Niklas

11 thoughts on “Drupal Statistics on Steroids”

  1. Thx for your great info. I made StatCounter module for drupal. Please visit my homepage. Any comments will be very much appreciated. Thank you verymuch and have a great day…

  2. I just signed up and installed the code using 4.7 . The steps were the same except that I had to allow the “script” and “noscript” tags in my FullHtml filter settings.

    The stats are great. Thanks again.

Comments are closed.