Using BBClone with Drupal 5 or 6

BBClone is to my knowledge one of the best stat counters freely avaibable. It is written in PHP, and it provides you with a wealth of information, is highly configurable, and doesn’t require you to mess with database tables. I find it to be very complementary to Google Analytics. It doesn’t offer the vast analysis possibilities that Google has to offer, but BBClone does provide you with more information about individual visitors, such as the keywords the used to land at your site. I’m sure there’s a certain threshold of daily visitors above which BBClone becomes a bit superfluous because the information is just too much, but when you’re below that threshold, it’s a bless.

One of the disadvantages of BBClone, however, is the fact that it cannot be included from within a function. To function properly, BBClone has to be called directly. Calling BBClone is done using:

<?php
define(“_BBCLONE_DIR”, “bbclone/”);
define(“COUNTER”, _BBCLONE_DIR.”mark_page.php”);
if (is_readable(COUNTER)) include_once(COUNTER);
?>

Optionally, you can define the refering page using:

<?php
define(“_BBC_PAGE_NAME”, “Test”);
define(“_BBCLONE_DIR”, “bbclone/”);
define(“COUNTER”, _BBCLONE_DIR.”mark_page.php”);
if (is_readable(COUNTER)) include_once(COUNTER);
?>

The pagename and the directory have to be changed according to your needs.

When you’re not caching your website at all, you can easily add this snippet to you page.tpl.php template, and that should work fine. In this case, you can even use the available Drupal functions to define the page name. When you’re serving your Drupal cached, then that’s not possible, however, as page.tpl.php is only called now and again (when the cache is being refreshed). If BBClone could be called from within a function, one could easily write a module calling BBClone during the bootstrap. Alas, that’s not possible. Therefore, the only possibilties to my knowledge require some core hacking. The one that I like the most, is messing with the main index.php file, because it’s a very simple file.
Right after the comment, you can add:

<?php
$bbrequest = strtolower($_SERVER["REQUEST_URI"]);
define(“_BBC_PAGE_NAME”, $bbrequest);
define(“_BBCLONE_DIR”,$_SERVER['DOCUMENT_ROOT'].”/statcount/”);
define(“COUNTER”, _BBCLONE_DIR.”mark_page.php”);
if (is_readable(COUNTER)) include_once(COUNTER);
?>

(Ofcourse, you don’t have to include the php tags.) The first two lines define the page name as the url requested from the server. Because the bootstrap has not even been initiated, using Drupal functions is not possible. One could write a more elaborate function to extract the page title, but I think this solution is both elegant and simple. And it works…

0 Responses to “Using BBClone with Drupal 5 or 6”


  1. No Comments

Leave a Reply