Part of our blogging series that helps new users and newbies how to setup and manage an online blog, this post is going to show you how to add Google Analytics tracking code to your sites to track user’s activities on your blog. Adding tracking code allows you to understand how your blog is doing with respect to visitors and usage.

If you’re new to online blogging, one motivational factor is to know how well you’re doing. You want to know who are you visitors, where they are coming from and how long they’re staying and reading your content. Finding out all of that, you’ll need an analytic program and Google Analytics is the most popular of all.

Now that you’ve setup blog and it’s running as expected, lets get started with adding Google Analytics. Before you can use the code, you must first sign up to use it. To sign up for Google Analytics, visit this page or search Google for ‘Google Analytics’

After registering, logon to Analytics and click the Admin page. There you’ll want to create a new web property. You first need to create a web property before tracking it. So create one and select the analytics JavaScript code to add to your site.

The tracking code should look like something below. Select the whole thing and copy.

<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', 'UA-4498753098', 'myonlineblog.com');
  ga('send', 'pageview');

</script>

 

When you copy it, logon to WordPress’ admin page and browse to Appearance –> Editor. Your default theme will automatically load. On the right where you have all the theme’s files, click Header (header.php).

 

google-analytics-wordpress-1

 

When the file is loaded in the editor,  look for the line that  </head> and add or paste the your analytics code just before it.

 

google-analytics-wordpress-2

 

It should look like the image above. The analytics code highlighted with green just before the </head> line.

When you’re done, save it and close out. It’s also a good idea to backup before doing this so you can restore the file in case something goes wrong.

After a few minutes or hours, you should begin to see some stats when you sign into Google Analytics.

Enjoy!