[[pageindex]]UPDATE: shout outs to Zach, Cliff, Justin, and Thomas who’ve submitted bug reports. Their feedback has been rolled in to the B4 July 20 release, available now (look for the link below).
This is likely the last release before the code gets bundled into bsuite (more details on that later).
Changes
This documentation supersedes any previous documentation.
More changes to the bstat_pulse() function; bstat_pulse_style() is no longer used. It’s been replaced by a flag in the call. See the usage example to understand. Want to customize the style? Start with that example, look at the XHTML it outputs, work from there. UPDATE thanks to Zach, these parameters are all optional. You can call it with nothing more than “bstat_pulse()”, if that’s your thing. Still, I’d recommend using the full example below.
There are a lot of improvements to the management console. The number of lines to display for each category and the date range (past day, week, month, etc.) are now configurable.
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}, {insert_styles});
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
insert_styles (acceptable values: 0 or 1), switch to output styles and wrap it in a div
Example:
<h3>
Story pulse
</h3>
<?php bstat_pulse($id, 525, 1, 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.
-
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: