Let’s face it, it happens to the best of us. Instead of bucking-up and doing a little extra work, we take a shortcut to save a few precious seconds and it comes back to hit us where the good Lord split us. I speak of course, of the inevitable WordPress plugin failure. Or more specifically, the inevitable bug-ridden WordPress plugin failure.One of the features that makes WordPress such a seductive option from which to build a website, is that even considering its advanced uses (and believe me, WP isn’t a sissy platform!) its relatively easy for non-developers to setup their own site. Most webhosts even had a one-click WP install method, making it even easier for people to get started. The what?If you’re like most WP users, you neither know nor care, how install a simple code snippet inside your template documents to add something as simple as Google Analytics. But with the great advancements and pure utility of GA, it makes sense that everyone would want to integrate it with their WordPress site. Thus, enter the Analytics Plugin…As with most utilities, there are a myriad of options available for including your analytics code via a plugin from the Plugin store. Far and away the most popular of such plugins is: Google Analytics for WordPress.  It ranks in with over 2.5 million downloads, which puts it in contention for most-used plugin in general. And it works! Quite well actually.

Except when it fails spectacularly!

Here’s the rub. The plugin has one big flaw. It gives you a fancy-pants front-end GUI to plugin in all sorts of options. One such option is to add in a custom _gaq.push statement.  When you enter a “Custom Code” definition, the plugin automatically adds slashes before all quote marks before storing the setting in the database. It then removes them when it displays the plugin.

The problem is if you change another setting and save the changes A SECOND TIME, the plugin erroneously adds in another 2 slashes. When the plugin is executed it’s not able to strip out all of the slashes and thus causes a complete failure of the tracking code. Hence, there’s NO DATA FLOWING INTO ANALYTICS! NICE ONE!

Here’s a simple solution…

Stop using unneeded plugins. A plugin to include google analytics is extremely unneccessary given the easy nature of adding your tracking code manually. Here’s how you can do that:

  1. Grab the analytics code from Google Analytics.
  2. Add in your custom _gaq.push statement(s).
  3. Use the built-in template editor inside wordpress or login via your FTP server and navigate to: /<wordpress directory>/wp-content/themes/<your theme>/header.php
  4. Open header.php file
  5. Paste the entire code snippet from step 2 right before <?php wp_head(); ?>
  6. Give a sigh of relief in knowing you no longer need to fear a freak plugin blowing up and rendering your important tracking data useless or nonexistent!
“plug” photo credit: copyright Samuel M. Livingston  / WordPress logo: Copyright WordPress.org