11/24 2016

How to Add Google Analytics to WordPress

64541065 - google analytics graphs on a tablet and a smartphone while working in the office

Google Analytics is one of the most popular ways to keep track of your website visitors. With Google Analytics, you can easily see where your traffic comes from, and what keywords brings visitors to your site. You can see how long visitors stay on your site, and much more. While there are a number of alternative analytic services out there, Google remains the most popular – and if you ever plan on selling a website, most people will ask specifically for Google Analytics access and data.

So how do you go about adding Google Analytics (GA) to WordPress?

Option 1: Add it to your theme

This is very simple way to add Google Analytics to your site. Simply go to Appearance->Themes->Editor and then look for the footer.php file. Paste your Google Analytics Code right before the closing body tag.

This isn’t the best approach. If your not familiar with how PHP or HTML works, you run the risk of damaging or breaking your theme. On the other hand, if you know coding, you can create a PHP include file with the GA code. Then you can just reference that before the closing body tag.

Many themes also have option panels, where you can paste the Google Analytics code. This means you don’t have to worry about editing the theme files.

While all these methods work, there is one big drawback. If your theme is ever updated, it will likely erase your GA code.  This could potentially cause you to lose several days, weeks, or even months of data (Depending on how often you check your stats!).

The other downfall to this method is if you decide to change themes, you’ll have to add it again to the new theme. That is why for most of my sites, I choose to go with another option for adding Google Analytics.

Option 2: Using a Google Analytics Plugin

Using a Google Analytics plugin, means the Analytics code is stored in the WordPress database, instead of being coded into theme files. This has two main advantages. First, you won’t have to worry about whether you change themes. Second, updates to your theme won’t erase the Google Analytics code.

You can use the WordPress Plugin Directory, to find the Google Analytics plugin you need:

https://wordpress.org/plugins/search.php?type=term&q=google+analytics

Choose a plugin that has the largest number of active installs, and has been recently updated. You’ll find that GA plugins fall into 2 types. There are lightweight plugins that just install the Google Analytics code. There are also plugins that not only install the GA code, but also provide dashboard stats etc. Personally I prefer plugins without stats, as they are lighter on resources – it really comes down to personal preference.

Here are some of the popular Google Analytics Plugins:

Google Analytics: The Google Analytics plugin by Kevin Kevin Sylvestre has over 600K active installs. It is super simple and lightweight on WordPress – so won’t slow your site down. You just need the web property ID from Google Analytics (UA-0000000-0). Fast and easy!

Google Analytics: With over 90K active installs, the PC Google Analytics plugin by Praveen Chauhan is another lightweight plugin. Just add the web property ID, and the plugin takes care of the rest.

Google Analytics Dashboard for WP: This plugin is for those who want GA stats right in their WordPress dashboard. Developed by Alin Marcu, it is a favorite among WordPress users, and has over 900K+ active installs.

Google Analyticator : Another GA plugin that’s been around for years. It provides Google Analytics and real-time statistics inside WordPress. Written by noahkagan, this plugin currently has over 300K+ active installs. However the plugin is now under the ownership of SumoMe, so is no longer open-source.

There are many other plugins that will add Google Analytics to your site. But these four GA plugins are top-notch, highly rated, and widely used.

Readers what’s your take? Do you prefer another Google Analytics plugin other than the ones mentioned here?

This post is written by Avrom Digance, founder and CEO at Web242 Hosting Ltd.


Subscribe to this feed  

Tags:   · ·

Leave a Comment