How to Add Google Analytics to WordPress

Google Analytics is one of the best ways that I have found to really track who is visiting your website. It gives you a clear view how users are getting to your site, how they interact with it, and how long they stay on it. This is one of the most important tools you need if you plan on doing any online marketing. After all, what is the point of an online presence if you don’t intend to use it?

Today, I’m going to show you how you can easily add google analytics to your WordPress site. You don’t need a custom theme to do it either.

Here is what we’re going to do:

  • Register with Google Analytics
  • Option 1: Install a plugin to do all the work for you
  • Option 2: Edit the code of your WordPress site

 

Register with Google Analytics

Here is the URL: http://www.google.com/analytics/

The first thing you’ll need to do is click on “Access Google Analytics”, then either sign up for a free account with google, or sign in with any of your other accounts you already have with them (Gmail, youtube, etc.). You should be on a page that looks like this:

Google Analytics Signup Page

Once you’re registered, click on the “Website” tab.

Google Analytics Set Up Page

In the Account Name field, you can just enter your or your business’ name. Once you fill out the rest of the form, click on Get Tracking ID.

You should now be looking at this page:

Google Analytics Tracking Info

This is where you have two options:

  • Use a plugin
  • Add it to the code of your theme

 

Use a Plugin

There are several great plugins out there that do great google analytics integration but the one I recommend most is Google Analytics Dashboard for WP. If you do go with this plugin, install it, and click on the logo in the menu bar on the left.

Click on “General Settings” and authorize the plugin with Google Analytics.

 

Add it to Your Theme’s Code

This part is not as tricky as you may think, but you will need some skills with editing files. The best way to add the tracking to your website is by editing your theme’s header.php file. Copy the tracking code from Google Analytics and paste it in the header.php file just before the closing </head> tag.

Your tracking code will look like this:

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'YOUR CODE GOES HERE', 'auto');
  ga('send', 'pageview');

</script>

Once you head back to the Google Analytics Dashboard you should see it start tracking data within 24 to 48 hours.

Let me know if you have any questions!

Happy Tracking