Automattic Stats for Movable Type

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.

When the entries would show up in my Global Dashboard, they had an ID, but they didn’t have a URL. I just couldn’t figure it out – the JavaScript that I was calling was just the same as what was being created by the WordPress plugin. I was about to give up again when I noticed that there was another function being called as the (WordPress) posts were saved that updated the information, sending it into the stats server. Maybe this did the trick?

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 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, 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 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 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">

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, 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!




7 responses to “Automattic Stats for Movable Type”

  1. Anil Avatar

    Nice work! Just as with TypePad AntiSpam, open services that benefit all bloggers can only be good for everybody, and I love how this shows off the vibrancy of the MT plugin community, as well as folks like you who aren’t religious about embracing good ideas no matter where they come from. ๐Ÿ™‚

  2. Chad Everett Avatar

    Mostly because I prefer the way it works, where I don’t have to write code to change the theme. I don’t have to install a plugin to update something, I can just add a tag.

    But beyond that, if I need a plugin, I can write one if I need to, and overall I prefer the – generally – static structure over the dynamic structure of WordPress (though I do publish parts of my site dynamically, just not the pages that are requested most often).

    Also, I can operate more than one blog out of a single installation of Movable Type, which I can’t do with WordPress (not talking WPMU here, because that’s really a non-starter for me).

    But there are places where I might consider using WP – the kids’ blogs, for instance. Enough of that. Any other blog-vs-blog bashing won’t be published, as that isn’t the point of this entry.

  3. human3rror Avatar

    The first question is… WHY use Movable Type in the first place…!??!


  4. Chad Everett Avatar

    @Andy –

    Thanks for the note, and for creating the stats system. I actually think it’s perfect for most casual blog users, so I’m just glad that I could put something together that people can use (hopefully :)!

  5. Andy Skelton Avatar

    Congratulations and thanks for writing this software! I take pleasure in quietly opening an API and waiting for it to catch on. MT users are welcome to use our stats system. We just can’t offer support beyond our usual capabilities. The usual disclaimers apply. Abuses will be handled on an individual basis. I hope everything works as expected. See the forums for discussion of the stats reports.

    Mileage varies, look both ways, etc.

    See also and if you automate queries to this URL please cache the results.

  6. Chad Everett Avatar

    @Toni –

    Glad you’re up and running Toni, let me know how it works out for you!

  7. Toni Hambilton Avatar

    Okay, I’ve set it up and am now waiting for the stats to show up. This is a cool way to use the API from WordPress since with the latest Mt 4.2 update we shouldn’t need to use Akismet anymore.