How to Add the Google Analytics Tracking Code to Your WordPress Blog
12 Aug
Google Analytics is a powerful tracking tool. With it you can track visitors and retrieve extremely useful data of your visitors behaviour.
But how do you add the Google tracking code to WordPress? I aim to give you an answer in this tutorial.
Get the Tracking Code
First of all you have to retrieve the Google Analytics tracking code. To do this you have to login to your Google Analytics account. Then click on the profile to which you have added your web site. If you have already created a new profile for the website then click on Edit at the right side. On the next page click on Check Status. There at the bottom you should be able to find the tracking code.
If you haven’t added the blog you want to track to Google Analytics then go ahead and click on Add New Profile. This will lead you to a new page where you have to enter the domain of your website. Enter it and leave the other options as they are and hit Finish. The final page will appear with the tracking code. The code should look like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Now once you have the tracking code just copy it. Now go to your WordPress blog and log in. Once you are in your WordPress dashboard click on Appearance -> Editor. When the new page shows up click on the header.php file on the right hand side. This will let you edit the header of your WordPress theme. Simply scroll down to the </head> HTML tag. Then paste the code, which you previously copied, above the </head> tag and click on Update File.
That’s it and Analytics should be able to track your visitors.











