Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-settings.php on line 530

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/therning/public_html/niklas/wp-includes/theme.php on line 623
Niklas blog » Blog Archive » Drupal Statistics on Steroids

Niklas blog

Just another WordPress weblog

Drupal Statistics on Steroids

May 28th, 2005 in Uncategorized

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

Deprecated: Function split() is deprecated in /home/therning/public_html/niklas/wp-content/plugins/google-analytics-for-wordpress/googleanalytics.php on line 466

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 Responses to “Drupal Statistics on Steroids”

  • Anonymous
    August 14th, 2005 at 22:55

    Thanks for the info! Appreciate it!

  • Anonymous
    December 16th, 2005 at 14:04

    you made my stats decision simple, and made it easy, too. drupal rocks.

  • Anonymous
    March 13th, 2006 at 22:35

    thanks a lot for this easy guide. 2ge/slovakia

  • Anonymous
    March 29th, 2006 at 05:51

    I was able to put this right to use on my site (http://isaacbowman.com). Thanks so much, Isaac

  • supriyadisw
    June 27th, 2006 at 11:59

    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…

  • Wolfgang
    June 29th, 2006 at 13:58

    Super - Thamks a lot.

  • Anonymous
    July 19th, 2006 at 20:05

    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.

  • Anonymous
    January 10th, 2007 at 14:30

    Thanks for this easy WOW and thank you for sharing it!

  • jimjam and sunny
    March 1st, 2007 at 14:33

    my kind of instructions man. A+

  • Pieter
    November 10th, 2007 at 16:06

    Still works in drupal 5.2
    Thanks

  • samy
    December 13th, 2007 at 22:09

    thanks for the info