Why You Should Never Add Analytics Code to Your WordPress Theme

This is a simple thing but it bears mentioning. Many major WordPress theme providers offer the ability to easily add Google Analytics or other tracking code via the theme’s options panel.

The idea stems from wanting to market a theme with everything needed to create the website that you see in the demo. Theme developers have been successful at selling themselves as one stop shops. To that end, they often pack WordPress themes full of code that is better suited to the realm of plugins.

One common example is a theme option to add tracking code. It’s likely one of the last options listed in your theme’s dashboard panel. It’s a really easy place to add Google Analytics code, but please resist the temptation to paste your code in here.

Analytics Code is Not a Theme Feature

Site analytics are not a theme feature and simply do not belong in your theme. Analytics has nothing to do with your website’s design. Even if Google tells you to add this to the header of your site, do not directly edit your theme.

The reason for this is that WordPress themes were made to be easily swapped out. More than likely you’re not going to use the same theme forever. But if your analytics code is in your theme options, then you’ll lose it when you change themes. By the time you realize it, you may already have large gaps in your analytics.

Do yourself a favor. Instead of adding the code to your theme every time you change themes, just drop it in a plugin. There are plenty available on wordpress.org. You’ll only have to add it once and it will be safe when you change the design of your website.

Theme Developers: Stop Tying Data to Themes

Portability – I has it

This discussion boils down to data portability, a topic of recent conversation on Justin Tadlock’s blog: Why custom post types belong in plugins. If you’re a theme developer, please do not tie any form of data or content to the themes you create. This includes analytics, shortcodes, custom post types, booking and event management, testimonials, fundraising functionality, portfolios, etc. The list could go on and on.

If a user cannot quickly pack up his data and go after using your theme, then your product has become a dead weight. In a perfect world, WordPress consumers will start looking at themes with this question in mind: “If I wanted to stop using this theme tomorrow, could all my data go with me?” If you’re selling a product that doesn’t pass that test, then you might want to make a few changes for the sake of data portability.

Better options would be to include functionality plugins with the purchase of the theme or recommend a high quality plugin to accompany it. Keeping those functions separate from the theme itself will help users to take their data with them when they change themes. As a bonus, it’s also easier to troubleshoot when providing support. Let’s just keep themes clean. We’ve all been guilty of hindering data portability in the past, but now is good time to start building WordPress products differently.