
A few months ago I wrote about using Statcounter on a WordPress blog. I had originally hoped to find a plugin to help with this, but in the end I had to roll my own “plugin” to get the job done.
I’ve been using Statcounter to collect data on the usage of my blog/website for a little over a month now. It’s an awesome tool! The graph at the top of this article shows the number of pageloads (green), unique visitors (blue) and returning visitors (orange) over the last month or so. I had no idea this many folks were reading this crap. Get a life, people!
Seriously, though… The traffic image above is just a nice graphic. The real value of Statcounter is the analysis tools they provide for your visitor log. My favorites are the “Popular Pages” and “Keyword Analysis” tools. Popular Pages shows your most-frequently accessed pages, duh. Keyword Analysis shows the search engine keywords that people are using to find your site and most importantly what pages they’re choosing to view.
In fact, the reason for this post is an analysis I ran this morning. A fair number of people are searching for “statcounter wordpress” and landing on one or the other of the two pages I mentioned in the first paragraph of this article. Further analysis of the Visitor Paths (another handy tool) shows that many of those people aren’t finding both of those articles. I’m hoping that this article will get a slightly higher page rank than the other two, and search engine users will more easily find the information they’re looking for.
A few days ago, Joseph and I were talking about bolting statcounter onto our blogs. He’s the one that pointed out statcounter to me, and all he needed to do was add the statcounter script to his theme’s footer.php file. This would probably work for any single-theme site, but I’m still running multiple themes on my blog. I need to do one of the following if I want to use statcounter:
- Drop all but one theme. There are several good reasons for this, most important of which is maintenance. This would allow me to add the statcounter script to the remaining theme’s footer.php and I’d be done.
- Add statcounter to all my themes. This probably wouldn’t be too bad, except for maintenance–whenever a new version of one of my themes came out, I’d have to manually reapply my changes.
- Write a plugin to insert the statcounter script in the footer of every page. This would be the most work up front, but it would give me a good excuse to learn how to write plugins for WordPress.
I found some useful resources for plugin authoring. The WordPress codex has a section on writing plugins. Owen’s tutorial is a great introduction–just read it and start hacking!
Carthik’s Plunge into Plugins article has lots of good advice, but isn’t a tutorial–check it out after/while you get started with Owen’s page. More good info is available on the Codex page Writing a Plugin.
I’ve started working on this plugin, and I’ve already been bitten by the “extra blank line” problem. (Admin interface was reporting “Cannot modify header information - headers already sent by…” error. Note to self–scroll to the bottom of each PHP file, and make sure the PHP close tag is right at the bottom of the file.) I have the code to insert arbitrary text into the footer, but I still need to add the Options menu which would allow J. Random User to edit the text to be inserted. (Right now, the text is hard-coded in the “plugin”, which I have installed and activated on this blog. Check the bottom left corner of any blog page for the statcounter.)
I don’t see any reason for this plugin to be statcounter-specific. It would be more useful to provide some sort of generic footer plugin which would allow HTML or javascript to be inserted in the footer. We’ll see how it goes. If I’m happy with it by the end of the night or later this week, I will go ahead and release it.
I’m thinking about using the free statcounter service on my site, but it requires that I add a little bit of javascript to each page. If I was running a single theme, I could probably find all the appropriate </body> tags and just paste in the statcounter code. But I’m trying to support multiple themes; besides, where’s the fun in cutting and pasting a bunch of code? Also, what if I need to change the statcounter code for some reason? So I think the Right Thing to do here is come up with a plugin for the wp_footer action which will insert some user-specified code, (in this case, my statcounter javascript). I haven’t found a plugin for statcounter, so I’ll be searching for a generic footer plugin. If I can’t find anything, I guess I’ll have to roll my own.