Web Design South Africa by The Yellow Llama » WordPress Consultants

web tips, blogs, funny pics... you'll find it all here

Feel free to grab our RSS feed. You must know, we don't post much, but what we do blog, is either helpful or funny... So its win win! You can explore the categories on the left, or just browse our latest articles below.

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).

bbcloneBasically 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 :)

burclar

great post thank you man

unodj

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);

Jaymus

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

Socorrito

Where axact i have to put the code in page.php or in wp-blog-header.php … i am using WP 2.7.

Post a comment on this blog

What The Yellow Llama Does Best

WordPress

We won't beat around the bush: We're damn good with WordPress. We can make it do pretty much anything. Contact us and we'll show you how WordPress can help you manage it.

Can The Yellow Llama Help You?

Whilst design & WordPress development are our forté, there's not much else we can't handle. If you need a completely custom application developed, why not give us a shout. If you can explain it, we can build it.

Noteworthy: Tech4Africa

TECH4AFRICA is a web & emerging technology conference, bringing global perspective to the African context.