bstat Beta 4 Release

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

Options

The bstat submenu of the options tab has three configurable settings:

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

Tags: , , , , , , , , , , , , , ,

44 thoughts on “bstat Beta 4 Release

  1. Thomas, thank you. I’m a sloppy coder and obviously need to spend a lot more time with the validator.

    The cs.ubishops server wasn’t answering my calls, but I think I worked out the problem. The code is now updated (version is b4 July 20), but please alert me to to any other problems.

    Thank you.

  2. how come when i put the bstat_hitit function in footer.php then i get this error?

    in /home/kahsoon/public_html/wp-includes/wp-db.php on line 155

    Warning: mysql_affected_rows(): A link to the server could not be established in /home/kahsoon/public_html/wp-includes/wp-db.php on line 155

  3. I ran into a couple of problems with the sample code in the footer. First, the comment line gave me errors until I changed it to the /* .. */ comment markers.

    And second, there was some kind of conflict with the $id variable that caused a user level conflict on one of my websites (but somehow worked on the other… go figure!)

    I also made a third mod, to check if the plugin is activated.

    Here’s the footer code as I revised it…

  4. Casey, this is really a wonderful plugin. The data is good, and the presentation is wonderful. I can’t gush about it enough, and I’m excited to see where you go with it.

    It’s easy to install and runs well.

    I’m sorry I’m having trouble posting the code that fixed the problems I was having… since I’m not sure how to mark it up for you. In case there’s something you find of interest, I’m posting the revised source at http://ryowebsite.com/wp-content/bstat.phps

    Here’s what I changed:

    Line 42 Changed add_management_page code parameter 2 to 6 (User Level… I moved up the level of who can see stats)

    Changed suggested footer code at line 157; Corrects $id error that was apparently resetting user_id somehow, fixed comment error; Checks for activated plugin; Counts page views as well as post views.

    Line 753 added strip_tags twice and … To correct for people who put html in their titles. (’cause I’ve got a guy who does that)

    Line 1040 added ‘plugins’ to path and changed name of spacer.gif to bstat.gif. I did that because it’s so much easier when it’s all in the plugins directory, and by renaming the gif I won’t forget what routine it goes with.

    Another issue/feature/question: Is there a way to determine how long a visitor stays on webpage? I don’t know if that’s even possible, but I suppose in some cases it might be possible is they came to a page, then clicked to somewhere else in the website. It would be interesting to know how interesting a story was. The current info tell sus how interesting the headline is.

    Thanks,

    Rich

  5. Matt,

    bstat is indeed open source as it is licensed under the GNU GPL. I’m not in a position to port it to Drupal myself, but I’d offer my code (it’s available at the download link above) and some assistance to the person who is.

  6. Casey, good job on this! As someone who is new to blogging/wordpress (and has little familiarity with PHP) this could not have been easier to install!

    Thanks for making this avalable!

    Jon

  7. Pingback: MaisonBisson.com » Blog Archive » MaisonBisson Top Seven

  8. Robert: yes, it is safe to overwrite any previous version with beta 4, however, beware of some of the changes to functions calls an update your templates.

    Work continues on bsuite, the collection of tools that is replacing bstat. Unfortunately, I’ll be changing more things — including table structure — so it will be a more complex upgrade.

    I’m glad you like it bstat, and I hope you’ll try bsuite when I finally release it.

  9. I just tried to install it, but when I click on the bstat submenu I get the following errors:
    beneath “Quick Stats”
    WordPress database error: [Table ‘soes.wp_bstat_hits’ doesn’t exist]
    SELECT SUM(hits_reads) AS note FROM wp_bstat_hits WHERE bstat_date = ‘2005-08-19’

    WordPress database error: [Table ‘soes.wp_bstat_hits’ doesn’t exist]
    SELECT SUM(hits_reads) AS note FROM wp_bstat_hits

    beneath “Pulse”
    WordPress database error: [Table ‘soes.wp_bstat_hits’ doesn’t exist]
    SELECT SUM(hits_reads) AS hits_reads, bstat_date FROM wp_bstat_hits GROUP BY bstat_date ORDER BY bstat_date ASC

    I am using WP 1.5.1.3 (letter head theme) and have several plugins installed, but no stat plugin so far.

    Any ideas?

  10. Antonio: be sure to complete each step of the quick start installation instructions, include the part of step four that that states

    visit the new bstat submenu of the options tab. This will allow bstat to create its database tables.

    Cheers!

  11. Thomas: yes, it’s a problem that I’ve half fixed. I hope to fully address it in my next release.

    Semester startup and other projects are keeping me busy, but I have been working on bsuite — née bstat — and hope to get a new beta out around the beginning of September.

  12. Pingback: The Medium Bagel » Blog Archive » More Fun with Wordpress Plugins

  13. Casey, i have a problem with your plugin:

    Why when i put the bstat_hitit function in footer.php then i get this error?

    in /home/kahsoon/public_html/wp-includes/wp-db.php on line 155

    Warning: mysql_affected_rows(): A link to the server could not be established in /home/kahsoon/public_html/wp-includes/wp-db.php on line 155

    Can you help me on this? I’ve been living with this quite some time.

  14. Kahsoon, I’m having trouble imagining where that error might come from in a working WordPress install. I guess I should add that I’ve not tested it on WP […]

    Update: Damn WP stripped the rest of my comment because of a “<” . I haven’t tested it in WP prior to 1.5.1.2 and I doubt it will work. The plugin uses all the standard WP stuff — including the wpdb function — so I’m not sure how it’s possible bstat could fail on any page that can display live WP content. Sadly, that doesn’t make it work for you.

    I don’t have any answers, but please post some more details about your setup. Maybe somebody in the WP community will see a clue in them.

  15. Pingback: rockersworld.com » Blog Archive » New Plugins Installed

  16. Pingback: matopc :: computing » WordPress Plugin: bstat

  17. Pingback: Hawk Wings » Blog Archive » Top 5 stories of the week

  18. Hi I was just wondering whether there was any special reason why you only tally for posts in bstat.

    I want counts for my pages too so I put in the check for is_page() as well.

    My counter seems to be climbing quite quickly though and I can’t decide whether it’s just because my site is more popular than I ever imagined, or whether I’ve screwed up.

    I only added the code to the footer, and it’s only the page that’s climbing (although it’s the only useful part of my website – a screengrabbing extension).

  19. re: Andy,

    I hadn’t thought of how pages might be counted until now (I don’t use them), so I’ll have to go back and look at how best to do so.

    In the suggested code above that calls hitit from the footer I’m basically checking to see if more than one post is being displayed on the page. This should be true for the front page, any category indexes, or a search page. In those cases I set the story id to 0 so that it can be counted without inflating the count of whatever post happens to be last in the list.

    I’ll take a look and see how it can be done better.

  20. Pingback: MaisonBisson.com » Blog Archive » bsuite_innerindex WordPress Plugin

  21. Pingback: Site AyntRyte » Site Stats as a Spellchecker

  22. Pingback: BorkWeb » Blog Archive » bstat Search Cloud

  23. Pingback: spiralbound.net » Google Analytics is Cool

  24. Pingback: bueltge.de » Blog Archive » WK - Google Analytics

Comments are closed.