How to add Google Analytics to Wordpress blog in the right way

 Date: July 14, 2014

I just found out, that Google Analytics was not counting my blog post pages. Only index page and all other subpages, but not post pages. This pages, which I am linking e.g. on twitter every time I blog!

From some time I was wondering if really only ~10 people are reading my blog. My last post about Getting started with iOS, was visited by 12 people in the day it was published and 10 in the day after.

iOS post stats

Then, on Google Analytics, I went to behavior > 'site content' > 'all pages' to check how many people visited the blog post page. And...there are no post pages in the statistics at all!

iOS post stats: pages

I knew that it is impossible, because at least I visited the post page. Then I checked statistics on Azure:

iOS post stats: Azure

There are no unique views, but even page views on Google Analytics shows less than 20 per day. I published the post around 11 am, and announced it on twitter 11:18am. Then I got 7030 requests between 12pm and 1pm. It makes sense. Of course 1 Azure request < 1 unique page view. According to Azure Management portal I had 62226 request in last week. How many unique pages views it is? I don't know and I will never know. But I am sure it is more than 54!

Why Google Analytics didn't track my posts? I put Google Analytics script in index.php file, in my Wordpress theme directory. Apparently I forgot to check if it works for all pages.

Now, I installed Insert Headers and Footers plugin to insert script from Google. As recommended in How to Install Google Analytics in WordPress for Beginners. It seems to be working fine now. Here are statistics from today:

iOS post stats: after Google Analytics script fix

There are also other plugins like Google Analytics for WordPress or Google Analyticator, but they insert Google Analytics snippet based on communication with Google api. It means, that if Google change their API for Google Analytics, plugin may not work. I don't want to be depend on that and just want to paste customized JS code I obtained from Google.

I also added Azure analytics script. Now, I will be able to cross-check the statistics.

 Tags:  blog

Previous
⏪ Getting started with iOS Development

Next
Installing Mac OS X in VMWare Workstation on Windows 8 ⏩