How to Create a Google Analytics Plugin for bbPress

bbPress is a free, open source forum software from the makers of WordPress. I am even using it on this site. It just came out of beta with the relase of 1.0. If you are looking for forum software I recommend it.

However, the theming system is not as simple as WordPress. I had added a Google Analytics script to my themes. But when I upgraded to 1.0, I lost all my tracking scripts.

The best way around this, I thought, is to create an analytics plugin. It turns out, it is very easy, especially if you have experience creating plugins with WordPress. The bbPress footer template has a hook for adding code to the footer. You just have to create the code that will add your tracking script to the footer of every page. That is it.

Here is an example of the code you can use. Download bbpress-analytics here. Just upload the script to your bb-plugins directory, and activate the plugin in the plugin admin. If you are using Google Analytics, all you need to do is replace “UA-XXXXXX-X” with your site code. But it will work with any tracking script, just replace the Google script with your own. Also you can use this same code to add any code you wanted to the footer.