Getting WordPress.com Stats Helper to work with JetPack

WordPress recently released their JetPack plugin which replaced WordPress.com Stats plugin. After upgrading, things took a bit to update, but most things worked fine afterwards. However, my Popular Posts widget (Most Viewed Posts) remained broken with the error: WordPress.com stats not installed

I was too busy this week to look into the cause of the issue and a quick search online didn’t result in much traction. This weekend, I finally got some time and found this post on WordPress forums: [Hack] How to use Stats Helper beside Jetpack.

Thanks to herophuong’s help, I realized what was causing the issue. The Most Viewed Posts widget is part of the WordPress.com Stats Helper plugin and it was looking up a function that no longer exists. When you installed JetPack, it automatically deactivated WordPress.com Stats. The helper plugin needed the API key in order to query for data.

You can either do what herophuong suggested in his post, but I thought a more elegant solution would be to create a separate plugin that created the function that it was looking for. That way when there are updates to the plugin, it won’t trample over your changes.

Stats API Key

All this plugin does is add the missing function stats_get_api_key and return the API key. After you download this plugin, you have to add your API key to the plugin.

You probably have an API key already. There are a couple ways to retrieve it.

  • apikey.wordpress.com
  • Akistmet settings – Go into your WordPress Plugins page and click on settings underneath Akismet

You can always go to apikey.wordpress.com to sign up for one if you don’t have one already.

After you download the plugin and obtain your API key, open the included stats-api-key.php and replace ENTER_API_KEY_HERE with your API key. Remember to leave the quotes.

Upload this file to your WordPress plugins directory (usually wp-content/plugins/) and go back to your WordPress Plugins Page, refresh the page if needed, locate the newly added Stats API Key plugin, and activate it.

Your Most Viewed Posts and any other thing that relies on WordPress.com Stats Helper should work now.

A couple things I noticed was it took a couple minutes for it to successfully retrieve the stats. Before it completed that, my most viewed posts widget would show my latest 5 posts. But be patient and it’ll eventually work.