Using BBClone with WordPress

BBClone is great website statistics application. I ran into a little trouble integrating it with WordPress, so maybe this guide will help you fix the same problems I was having.

Symptoms:

  • It’s not working at all!
  • The page names are pretty much useless
  • In the global stats page, all the links point the blog root

First of all, here is how you 1) get it working, and 2) fix the page names to something more useful. There were other suggestions on the WordPress support forums, but I find this way to be the best. This is mainly because it it makes it more similar to my Apache logs (it uses the full path/file as the page name).

You’ll have to make changes to a lot of your theme’s files, so you might want to back up your theme’s directory before getting started. This guide is catered towards the Kubrick theme (and modifications of it that stick to its basic framework).

Open up the following files from your theme’s directory: 404.php, archive.php, archives.php, attachment.php, index.php, links.php, page.php, search.php, and single.php. I guess that 404.php would be optional, but I personally am curious about people landing on non-existent pages.

Near the top of each of these files, you should notice the following code:

<?php get_header(); ?>

Replace that line, and only that line, with the following code:

<?php
define('_BBC_PAGE_NAME', $_SERVER['REQUEST_URI']);
define('_BBCLONE_DIR', '/path/to/bbclone/');
define('COUNTER', _BBCLONE_DIR . 'mark_page.php');
if (is_readable(COUNTER)) include_once(COUNTER);

get_header();
?>

Don’t forget to change “/path/tp/bbclone/” to the correct value! If you need help with doing that, leave a comment. If you see something like this at the top of any of the files…

<?php
/*
Template Name: [NAME]
*/
?>

…then leave that part of the code the way it is. Only change the part mentioned above.

For advanced users, if you have other files that contain the get_header() function, make the modification to them as well. If you add more template pages in the future, don’t forget to include the BBClone code.

By default, BBClone truncates page names at about 57 characters (and adds an ellipses). I thought that was too small a number since I’m using the full paths as the page name. Here is how you change it to around 150 characters:

Navigate to the BBClone directory, and open the file named log_processor.php. You should make a backup of this file before you continue. Around line 116 of log_processor.php, you should see the following code:

  $over_60 = ((defined("_BBC_MBSTRING") ? mb_strlen($long_page) : strlen($long_page)) > 60) ? 1 : 0;
  $connect['page'] = $over_60 ? "...".(defined("_BBC_MBSTRING") ? mb_substr($long_page, -57) :
                     substr($long_page, -57)) : $long_page;

Replace that code, and only that code, with the following:

  $over_150 = ((defined("_BBC_MBSTRING") ? mb_strlen($long_page) : strlen($long_page)) > 150) ? 1 : 0;
  $connect['page'] = $over_150 ? "...".(defined("_BBC_MBSTRING") ? mb_substr($long_page, -147) :
                     substr($long_page, -147)) : $long_page;

That takes care of everything except for the problem with the global stats. I have a workaround for that, but I am not going to post it yet, because it is not fully tested. What I’ve done may have been a very bad idea, so it would definitely not be a good idea to share it on here until I can guarantee that it’s safe. If you are curious about the workaround, leave a comment and I’ll send it to you in an email. You don’t need to include your e-mail address in the comment, just make sure you include it in the E-mail box.

Please post any suggestions you may have to improve or replace this integration method.

Note: If you are using WPG2, there are a few extra steps involved in getting the stats displaying in your gallery. I’m not going to post them unless someone leaves a request in a comment. That will remind me to do it. UPDATE: This was posted before I started using Google Analytics, and before I upgraded WordPress to the latest version. I can still do what I can to help, but I may not remember details.

22 Responses to “Using BBClone with WordPress”

  1. Henri Says:

    Hey nice tutorial, no probs modifying the files.
    Didn’t work for me, though. I guess I’ll leave the files modified anyway since it didn’t break anything.

    Do you think it might have anything to do with what versions of BBClone &#38; WP you run? Anyways, I’m using BBClone 0.4.8a-utf8 and WordPress 1.5.2 with a theme based on Kubrick. Page hits show up, but only as Main Site pages.

    Thanx anyway.

  2. chrisb Says:

    Interested in that global stats fix for the home page as it would make tracking users that little bit more efficient.

    Thanks for the code so far… excellent work.

    Cheers :)

  3. Dan Says:

    @Henri
    Hmmm, for some reason I didn’t see your comment before.. Well, I’m running WP2, but I’m not sure that it should be the reason for the trouble. I’m not sure, but are you talking about the links on the main stats page? Those require another fix that I really can’t post because it hasn’t been thoroughly tested (and the BBClone forum is pretty much dead). If you would like to see it, though, I can show you. Personally, I’m thinking of looking for another solution other than BBClone. I’m having a lot of trouble getting any support, but can’t complain because it’s free :-].

    @chrisb
    The files have been sent, as you know. I’m just adding this comment so that future visitors don’t think that they will be ignored! hehh

  4. Henri Says:

    @Dan
    I do get hits, but the hits are, as you say, pretty useless since they all get recorded as hits to the wp-root, eg. main page. I upgraded to WP2 recently, so I’ll try this again. It would be nice if you could mail me the global stats-fix so I could give that one a shot too.

    Have you had any trouble with your stats resetting because of heavy load from ‘bots and crawlers? I checked the BBClone forums, there are a couple of others experiencing the same stats-getting-reset, but no fix so far that take scare of the problem.

    Thanks!

  5. Dan Says:

    Henri, I sent you a message with the information about the global stats page. If that doesn’t fix the other problem you were talking about, just let me know via email…

    As for the bots and crawlers, I’ve finally disabled the logging of robots in the BBClone configuration. I don’t know whether that will fix the resetting issue, though. Actually, the only explaination I can think of for that problem is a file-locking issue. My guess is that if someone accesses the site and the access log file is not locked properly, then someone else comes along at the same time… It might overwrite everything. I’m not entirely sure, though, as I haven’t run into that problem before. It is possible to change the locking behavior in the BBClone config.

  6. Henri Says:

    Thanks Dan, got it up &#38; running now!

  7. ob Says:

    Thank you for the code, however, after I put into the files, I can not find the bbclone, should I put the bbclone into the root directory or the wp-content directory? I put the at root directory and the ‘/path/to/bbclone/’ set to ‘bbclone/’, is it correct? Or did I need to change any other thing?

  8. Dan Says:

    ob, I think the best idea would be to put it in your site root. That would keep it separate from your Wordpress installation.

    Also, the /path/to/bbclone/ is actually the filesystem path. So that’s different from the URL path. e.g. - the URL path for this site is just /blog/, but an example of a filesystem path would be /home/username/directory/blog/.

    One way to find out your filesystem path is to save a php file in the same directory as your BBClone installation. Put the following code in the PHP file:

    echo $_SERVER['DOCUMENT_ROOT'];

    You may have to add a directory such as bbclone/ after the path that is returned by this script. That should hopefully work.

  9. ob Says:

    Thanks Dan. However, I still can not get the bbclone work. When I open the olympicbaseball.com/bbclone, it still show 404 error. Does it happen because I install the wordpress at the root directory? Or any other directory I can use? Sorry to bother you again.

  10. Dan Says:

    Hmm, it may be best if we took care of this via email. I may need to see at least a portion of your .htaccess file. I assume that you’re absolutely sure that BBClone has been installed into that directory. My email address is contact@soulpass.com

  11. heinzg Says:

    Hi, Thank you for the good howto. All is working as you have mentioned it would. Could I ask for that global stats fix? &#38; what are the risks in using it.

    Many Thanx
    Heinzg

  12. Dan Says:

    Thanks for commenting, and glad it’s working! I’ll send you the global stats fix… As for the risks, I’m really not sure. No one ever helped me in the BBClone forums…

  13. heinzg Says:

    Hi Dan,
    Cheers for the fast responce. I have added the fix. but in the global stats I still get this kind of output “/?cat=1″ for pages visited. You have any ideas on this?

    Many Thanx
    Heinzg

  14. Dan Says:

    Ahh, that’s actually because mod_rewrite is disabled in your WordPress install… Hopefully your host allows you to use custom .htaccess directives. If so, here’s how you enable “friendly URLs” (using mod_rewrite in .htaccess):

    1) Go to your WP Admin
    2) Options
    3) Permalinks
    4) Right now you’ve probably got “Default” selected there… Try changing it to “Date and name based.” That should hopefully do the trick. Not only that, but it should help you get better search engine rankings.

  15. Henrikf Says:

    Hey !! Great …i will intergrate this right away …

    But pls pls … let me knew how to integrate it on my WPG2 side …
    (Integrate it on the regular main.php works great but .. that dont show up i wp :-)

  16. Dan Says:

    Try this… Open up wp-gallery2.php. Look for this section:

    //Include current WordPress Theme Header etc.
    require('./wp-blog-header.php');

    In mine it’s around line 29, but I may have moved things around some.

    So… Right under that section, add this:

    define("_BBC_PAGE_NAME", $_SERVER['REQUEST_URI']);
    define("_BBCLONE_DIR", "/path/to/bbclone/");
    define("COUNTER", _BBCLONE_DIR."mark_page.php");
    if (is_readable(COUNTER)) include_once(COUNTER);

    I think that’s all it took, but I could have forgotten something. I need to start writing these things down as the changes are made! Hopefully it will do the trick… Once you do that, all your stats — from your blog and from your gallery — should display in BBClone together.

  17. Henrkf Says:

    Sweet .. that will get me rolling !!!

    Tnks for the help ..

  18. Hendricus Says:

    Hi,

    I came accross this site when I was trying to find a solution for the problem that the links to the top 10 visited pages aren’t working correctly. I’m using my own cms but I guess my solution will work for all you wordpressers out there…

    Find the marker.php BBClone page.
    On line 275 replace:
    $BBC_TIME_OFFSET;
    with
    $BBC_TIME_OFFSET, $BBC_MAINSITE;

    And on line 321 replace:
    $REQUEST_URI = $this-&gt;filter_uri($filename, $PATH_INFO , $PHP_SELF);
    with
    $REQUEST_URI = $BBC_MAINSITE.$_SERVER['REQUEST_URI'];

    Ofcourse this needs the $BBC_MAINSITE variable in the config.php to be set to your domainname. If the $BBC_MAINSITE variable is set to something like: http://www.soulpass.com/username/site/ you might be better of changing line 321 to:
    $REQUEST_URI = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; and forget about the change on line 275

    This works for me. Test it yourself first before you screw up your stats!
    Like they say: Past performance is no indication of future results!

    Hope this helps anyone!
    Cheers form the NL

  19. Dan Says:

    Thank you for the contribution!

  20. Calvin Gilbert Says:

    This works like I charm! I am forever in your debt.

  21. Dan Says:

    Glad it was helpful :-)

  22. Adam Kinney Says:

    The issue I have is that I only display the main page, when i click to another page it just shows the reload in bbclone not the next page. Any thoughts?

    Using WP 2.6
    bbclone .4.9c

Leave a Reply