If you read the post where Andy talks about releasing the Automattic stats plugin for self-hosted WordPress, he mentions a few things that make it interesting – notably that the system “only supports WordPress”. Then he also mentions that anyone with a thorough understanding of WordPress and XMLRPC could clone the plugin to make it work with other platforms.
I don’t claim to have such knowledge (of either WordPress or XMLRPC), but I think I’ve managed to do just that. Make it work with another platform, I mean. Some time ago, I managed to get the blog registration piece working, which really wasn’t that hard – you simply pass some data to the system along with your API key and in return you get your blog registered. Not too bad. Then I ran into a speed bump of rather monumental proportions. Actually it wasn’t that the bump was particularly large, it’s that I hit it and then had about a million other things to do. So I put everything on the back burner.
Solving the Puzzle
The other day I picked up the plugin again to see if I could find anything new that would help me figure out the problem. I absolutely hate it when I can’t figure things out, after all, and perhaps after sitting for several months I’d be able to get this one solved.
My first issue was that I had to rewrite everything to work correctly with MT4 – it had really been that long since I had looked at it. That alone took a lot longer than it should have. The good news is that it gave me the chance to rework some things that weren’t working and modernize some other parts so that they worked better. But I still had another problem in that, even though the stats were tracking, they weren’t tracking right.
I was actually able to replicate this function pretty quickly, but then I screwed it up by inserting the Movable Type blog id, rather than the WordPress.com blog id – which led to hours of troubleshooting other issues. When I finally realized what I had done, I was able to get the (Movable Type) entry information updated, and suddenly instead of entry ID information on WordPress.com, I suddenly had titles and URLs. It was all very exciting – though I realize it is probably much more so to me than to you.
So without further ado, I bring you the first public release of MT-WPStats. If you’d like to try it, download it and unzip it to your Movable Type plugins directory. You’ll end up with a WPStats folder, which contains the WPStats.pl file and a tmpl folder that contains several other files. These are necessary for the proper operation of the plugin.
The API Key
The first thing you need to do, if you haven’t already, is head over to WordPress.com and get yourself an API key. If you use Akismet, it’s the same thing – you don’t need another one. Once you have your API key, visit your blog-level plugin settings screen (Preferences -> Plugins) and click on MT-WPStats, then Settings. Click on the link to Set your WPStats API Key.
From the dialog, enter your key and click Connect. If everything goes well, you should receive a message to that effect. If not, you may receive one of several messages telling you how to correct the problem, with as much information as possible. Once you are done, you’re ready to continue.
Adding the Template Tag
Simply open up your Entry template (perhaps named Individual Entry Archive, depending on whether you upgraded or not) and add the <$MTWPStats$> tag to the code wherever you like. Near the bottom, just above the closing </body> tag, is typically a good place to put it.
For the default templates, you should actually open the Footer template module, and use code similar to the following, just above the closing </body> tag:
<MTIf name="entry_template"> <$MTWPStats$> </MTIf>
This way, it will only be included if you are in an entry template – but not in an index or a listing template.
Those Pesky Entry Details
Once the template tag has been added, you’ll need to rebuild your templates (at this time, the plugin is only available for static archives, not dynamic), and once you have done so, statistics will start being sent almost immediately to the Automattic stats server. However, if you log into your Global Dashboard, you will notice that you have only entry IDs, and the URLs are not correct. This is because those details are not sent on every page load (or statistics update), but when you save your entries. So in order to get those correct, you will need to re-save any entries already in the system.
You don’t have to do this step – only if you want existing entries to be correctly reflected in the stats system. In other words, if you don’t do this, expect to see some odd-looking data in the stats system. Any new entries will be fine, but those older entries will look odd, with numbers instead of titles, and without correct URLs. But once you have re-saved them, the updated information will be sent, and you’ll be good to go. You can do this at any time – even once stats have already been sent or a URL changes – and it will be updated on the stats server!
But Wait – Is This Okay with Automattic?
Uh, I don’t know. That post that Andy made says that anyone who abuses the system, causes undue loads or inflicts headaches, will be subject to having their API key revoked. I’m not giving you my key, so you’ll have to use yours. I hope that you use it responsibly. It is certainly possible that they figure out who I am, simply because I’m releasing the plugin from my own site, under my own name, but as I don’t really use the service, except to test it out, and I don’t even use Akismet anymore, I’ll get over it.
I’m hoping that they don’t, because I’m thinking that the more people who can do the more stuff, the better. I’m not a big fan of MT-only-this or WP-only-that. I just think it’s cool that Movable Type users can use a service built for WordPress, just like I think it’s cool that WordPress users can use the new TypePad antispam service. Hopefully they’ll agree. If not, well, we may have an issue. Still, you may not want to close out your Google Analytics account just yet.
Update: I have spoken briefly with someone at Automattic, and they seem to be okay with it, assuming you aren’t completely abusing the service, and as long as I mention that the plugin is using WordPress.com, it’s okay (and I think I’m pretty clear about that). So just be smart about it and everyone should be happy.
Another Update: Matt himself mentioned the plugin on his blog (thanks to those of you who pointed it out). Though he didn’t spell WordPress right, I guess that’s about as close to a seal of approval as it gets, along with Andy’s comment below. So go for it. 🙂
And Another: I have a version that should work with with MT 3.3x (specifically 3.36). If you want to try it out, let me know and I’ll send you a version that you can test. If enough people tell me that it seems to be working, I’ll release it to the public. Thanks!