BBClone & Wordpress Integration
BBClone is a rocking piece of software. Its a website statistics generator that provides highly detailed listings of each & every visitor to your site: their IP, Location, Time of Visit, OS, Browser, Time spent, Pages viewed, Referrer and Search Term used (if applicable).
Basically you put a trigger on each page of your website. That trigger has a unique key/name that identifies that specific page so you can easily identify in the logs which pages have been viewed.
The Problem
It gets a bit tricky though, when you’re using templates like you have in Wordpress.
single.php is the template used for blog articles in Wordpress. That 1 file is used in the creation of 1000’s of blog articles. So how can you integrate BBclone with Wordpress so that you know which blog articles are being viewed?
The Solution
…Well let me first state that is isn’t the once-and-for-all-time solution to this problem. I’m sure that using the the_title(); tag, there is a better way, but until somebody shows me that way, I’ve found this way to work for me…and besides, its painfully easy.
Here’s the BBClone trigger
define("_BBC_PAGE_NAME", "Page Name");
define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
Generally, that piece of code goes onto your page and “Page Name” becomes the unique identifier in the BBclone logs.
Here’s what you do so that you can dynamically create a unique identifier based on the URI of your blog article…
define("_BBC_PAGE_NAME", $_SERVER['REQUEST_URI']);
define("_BBCLONE_DIR", "bbclone/");
define("COUNTER", _BBCLONE_DIR."mark_page.php");
if (is_readable(COUNTER)) include_once(COUNTER);
Presto. Done.
That’ll generate a unique identifier from the URI (or in Wordpress lingo, the ’slug’) of your page. So in my BBclone logs for this post, I’ll see /bbclone-wordpress-integration/.
Ja I know its not pretty, but for now it does the job just dandy :)
3 Responses to BBClone & Wordpress Integration
great post thank you man
for nice titles in the stat list, use this code :)
function nice_bbc_titles() {
$uri = !empty($_SERVER[’REQUEST_URI’]) ? $_SERVER[’REQUEST_URI’] : “index”;
$uri = strtr(strip_tags($uri), array(”\r” => “”, “\n” => “”, “\\” => “/”));
$uri = str_replace(”$”, “$”, htmlspecialchars($uri, ENT_QUOTES));
$uri = trim(substr($uri, 0, 256));
if (!is_string($uri) || empty($uri) || ($uri == “/”)) return “index”;
$uri = (substr($uri, -1) == “/”) ? substr($uri, 1, -1) :
((($dot = strrpos($uri, “.”)) !== false) ? substr($uri, 1, –$dot) :
substr($uri, 1));
$uri = strtr($uri, array(”/” => ” :: “, “_” => ” “, “-” => ” “));
return ucwords($uri);
}
# actual code
define(”_BBC_PAGE_NAME”, nice_bbc_titles());
define(”_BBCLONE_DIR”, “bbclone/”);
define(”COUNTER”, _BBCLONE_DIR.”mark_page.php”);
if (is_readable(COUNTER)) include_once(COUNTER);
Good suggestions, I think I like what I found over here more: http://www.iltchev.com/?page_id=11
backup: http://wordpress.org/support/topic/116866?replies=5#post-731227
Leave a Reply