Google Analtyics: Hard Coded or Plugged In?

I’ve received several questions from clients about their google analytics setup. The big question is where should they put in their code? I’ve seen developers state that you need to put in your code in the header.php file of a theme, which is normally what I would say. But I’ve come across something that has changed my mind about that.

What happens when you change themes?

I know I like to try out different themes from time to time, or even test drive the new WordPress default themes when they are released.  Many of my clients use free themes and change the look of their site constantly. The problem lies that their google analytics code is embedded in the header.php file of their theme, so if they change themes, they will lose the tracking code, and all tracking of their sites will stop.

Luckily, it’s an easy fix, but something that doesn’t need to happen. You need to separate the essential functionality of your site from the theme files. This means you need to have a plugin to add your code to. If you change themes, your site will still be tracked.

For Google Analytics, I highly recommend Yoast’s Google Analytics plugin.

If you want the ability to add code to your wp_head and wp_footer, I am actually writing a plugin that will help you with that, so stay tuned for that!

Leave a Reply