UPDATE: bstat has been updated.
Beta 2 never went public. This is beta 3.
Changes
This documentation supersedes any previous documentation.
The bstat_pulse() function has been improved and now uses your CSS for appearance. Call bstat_pulse_style() to add my default styles inline if you don’t want to modify your CSS. Also, bstat_pulse() now has two switches to control what it displays. Please take a look at the usage guide below for how to call this function now.
Also, take note of new example of how to call the bstat_hitit function: “if(is_home())” has changed to “if(!is_single())”. This corrects a problem with the way bstat was recording activity on any page with more than one story (search, archive, etc).
The next two features are for Zach. Links generated by the functions now use your WordPress permalink preferences instead of the ?p=XXX stuff.
It is now possible to exclude certain IP numbers from your hit counting. You’ll see controls for this in the bstat submenu of the options tab.
Search engine highlighting snuck into the last release, but has been buggy for some. It’s disabled in this release and will eventually be folded into a new plugin called bsuggestive. Yes, it’s bsuggestive. If you’d like to play with it, you can uncomment the likely looking line at the bottom.
There’s some ad tracking code in there, but I’m leaving it undocumented for now.
Quick Start Installation
- Download and unzip bstat.zip
- Place bstat.php in you wp-content/plugins directory
- Place spacer.gif in your wp-content directory
- Log in to your WordPress admin panel and activate the plugin, then visit the new bstat submenu of the options tab. This will allow bstat to create its database tables.
- Add the bstat_hitit function to the footer.php of your theme (or in some other place where it will be called once for each page load). This starts the counting; you can see the results in the bstat submenu of the manage tab of the WordPress admin panel.
In order to view the bstat results on your public pages, you’ll need to the bstat display functions to your pages.
Using bstat Functions
- bstat_hitit
It is essential that bstat_hitit be activated once (and only once) for every page load. In most themes (including the default and classic), it works perfectly when added to the bottom of the footer.php file.
<?php // this is the part that makes the bstats plugin work...
global $id;
if (!is_single()) $id = 0;
bstat_hitit($id, "read");
?>
(be careful of any “curly quotes” that might have been inserted in code samples)
Other functions are used to display lists of top stories, recently commented stories, recent comments, recent incoming search terms, etc. Most of these functions take similar arguments and output their results in similar ways.
Today’s Stats
- bstat_todaypop
- bstat_todayrefs
The functions bstat_todaypop and bstat_todayrefs each take the same arguments.
Usage:
bstat_todaypop({count}, “{before}”, “{after}”);
count is the total number of results to output
before is a string to output before each result
after is a string to output after each result
Example:
<h2>
Today's Most Popular
</h2>
<ul>
<?php bstat_todaypop(15, "<li>", "</li>\n"); ?>
</ul>
Recent Stats
- bstat_recentpop
- bstat_recentrefs
The functions bstat_recentpop and bstat_recentrefs each take the same arguments.
Usage:
bstat_recentrefs({count}, “{days}”, “{before}”, “{after}”);
count is the total number of results to output
days is the number of days back to look
before is a string to output before each result
after is a string to output after each result
Example:
<h2>
Incoming Search Terms This Week
</h2>
<ul>
<?php bstat_recentrefs(15, 7, "<li>", "</li>\n"); ?>
</ul>
Recent Discussion
- bstat_discussionbypost
- bstat_discussionbycomment
The functions bstat_discussionbypost and bstat_discussionbycomment each take the same arguments.
Usage:
bstat_discussionbypost({count}, “{before}”, “{after}”);
count is the total number of results to output
before is a string to output before each result
after is a string to output after each result
Example:
<h2>
Incoming Search Terms This Week
</h2>
<ul>
<?php bstat_discussionbypost(15, "<li>", "</li>\n"); ?>
</ul>
Special Functions
- bstat_refsforpost
Usage:
bstat_refsforpost({post_id}, “{before}”, “{after}”);
post_id is the post_id for the story, usually provided by a WP variable
before is a string to output before each result
after is a string to output after each result
Example:
<h3>
All incoming search terms for this post
</h3>
<small><?php bstat_refsforpost($id, " ", " -"); ?></small>
- bstat_pulse
Usage:
bstat_pulse({post_id}, {max_width}, {display_text}, { display_credit});
post_id is the post_id for the story, usually provided by a WP variable
max_width is the maximum width the graph maw run
display_text (acceptable values: 0 or 1), switch to display stats for total views and average views per day
display_credit (acceptable values: 0 or 1), switch to display “powered by bstat” credit
Example:
<?php bstat_pulse_style(); ?>
<h3>
Story pulse
</h3>
<?php bstat_pulse($id, 525, 1, 1); ?>
Function Descriptions
-
bstat_hitit The hamster on a wheel that makes it all work. It records hits for each page load, and hits for each incoming search term.
-
bstat_todaypop displays top stories for today only.
-
bstat_recentpop displays top stories for the past x days. This function reveals more useful data on sites with low traffic, but is somewhat slower than bstat_todaypop.
-
bstat_todayrefs displays top incoming search terms for today only.
-
bstat_recentrefs displays top incoming search terms for the past x days. This function reveals more useful data on sites with low traffic, but is somewhat slower than bstat_todayrefs.
-
bstat_refsforpost displays all incoming search terms for a specific post.
-
bstat_discussionbypost displays recently commented posts. Each post will appear only once.
-
bstat_discussionbycomment displays recent comments (and commenter). Better on sites with lots of community interaction.
-
bstat_pulse displays the “pulse” graph of hits over time.
-
bstat_pulse_style outputs an inline stylesheet for use with bstat_pulse. Suggestion: activate this to see what the default styles are, then add them to your site’s stylesheet and work from there.
-
Make accurate pulse graphs The graphs look best when you’ve got a few months of history to feed them. To fill out the graphs for new stories (and when you’re new to bstat), the pulse function will do some simple interpolation. The question here is if you want it to look jittery (and somewhat less accurate) or smooth (and more accurate). I prefer the jittery look, but you can do what you want.
-
Filter incoming search terms using comment moderation and blacklist words. Referrer spam is as much of a problem as trackback spam. There are a few tricks in bstat to prevent the problem, but here’s one you can configure. Selecting this option tells bstat to not display search terms that contain words in your moderation list or blacklist.
- Ignore hits from these IP numbers. Sites with low traffic may find that activity by authors severely skews the stats tracking. Enter an IP address here to ignore it.
Options
The bstat submenu of the options tab has three configurable settings: