Love it or hate it, you really should be using Google Analytics on your WordPress site.
Even though the dark overlords at Google have restricted a lot of the data that used to be available in Analytics, it’s still an extremely valuable tool for gathering intelligence on your site visitors. Analytics can show you where they landed, what they read, how long they stayed, what they were searching for, and a heap of other valuable stuff.
As a serious WordPress blogger who aspires to greatness, you really can’t afford to be without it. This article shows you how to add Google Analytics to WordPress with minimal fuss and very little effort.
Step One: Get a Google Analytics account
If you haven’t already signed up for analytics, you’ll need to venture over to Google and get hooked up with a free account. Don’t worry, it’s quick and painless.
Once you’ve completed the sign up process, you’ll be given a piece of JavaScript code. It looks like this:
Featured Plugin - WordPress Ecommerce Shopping Cart Plugin
Step Two: Add the Google Analytics code to your WordPress theme
To do this, you’ll need to open up the footer.php file of your WordPress theme. You can either use an FTP client to access your server, or edit your theme files directly from the WordPress dashboard. Your file editor is located under the ‘Appearance’ tab in the sidebar menu.
In the list of template files to the right of the text editor, find footer.php and open it. To add Google Analytics to WordPress, you now just need to copy and paste your code immediately before the closing </body> tag. Like so:
Make sure you save your footer.php file once you’ve pasted in the new code. Google Analytics should now be able to track every page of your WordPress site and provide you with that sweet juicy data.
Step Three: Double check that your analytics is working
To make sure that the script has installed correctly, go back to your Google Analytics home page and click the admin panel in the top right corner of the screen. Open the relevant account, and click the ‘tracking code’ panel. If the Tracking Status is ‘Receiving Data’, then you’ve successfully added Google Analytics to your WordPress site.
Featured Plugin - WordPress Newsletter Plugin
Alternatively, use a Google Analytics plugin
If you’re not comfortable hacking around in your WordPress template files, or you want to explore some additional options and functionality, you can also add Google Analytics to WordPress with the use of a plugin. These plugins will typically give you an interface in your WordPress dashboard where you can add the code directly, without having to delve into your theme files.
There are quite a few Google Analytics plugins to choose from, and I wouldn’t necessarily recommend one over the others. Have a look for yourself in the WordPress plugin directory. If you have a multi-site solution, I would also suggest checking out WPMU Dev’s Multisite Google Analytics plugin.
Photo courtesy of Flood.





Not sure why you say in the footer if Google recommend to put before
the end of head
You can go with either option. Some folk recommend the header, others recommend the footer.
One argument for putting the code in your footer is that it doesn’t count a page visit until the whole page has loaded, giving you more accurate stats on who is actually looking at your content.
It’s much of muchness though – you’ll be fine putting the code in either the header or the footer.
Cheers,
Tim
Ok thanks for answer!.
Actually for wordpress the best way to add google analytics code is in functions.php file. here is a snippet you can use.
// add google analytics to footer
function add_google_analytics() {
echo '';
echo '';
echo 'var pageTracker = _gat._getTracker("UA-33333333-3");';
echo 'pageTracker._trackPageview();';
echo '';
}
add_action('wp_footer', 'add_google_analytics');
Offcoase you want to use your numbers not the sample one above.
I am using the plugin method to add our WordPress blog with analytics. would you please tell me if I paste the code into the plugin where it goes to, means in footer or header. I am using the method mention in the below source,
http://www.wordpressians.com/add-google-analytics-to-wordpress/
Mohammad, it is really simple just copy and paste the code into the plugin code area.
That’s bad advice. Don’t edit your theme if you can use a plugin. Switch to a different theme and your analytics will stop working. The themes and plugins editor in WordPress is a recipe for disaster too. There are a bunch of Google Analytics plugins out there, Yoast’s doesn’t ever require you to copy/paste your tracking code, it logs you in with OAuth and asks you to select your Analytics profile, very user friendly. Don’t reinvent the wheel and stop this “without a plugin madness” kthx bye :)
Related: http://kovshenin.com/2012/plugins-vs-without-a-plugin/
~ Konstantin
Copying the GA code into your new WordPress theme would take all of about thirty seconds, so I don’t see that as much of a disincentive.
If you prefer using a plugin, that’s fine and dandy!
It’s not just a matter of preference. You follow enough of these tutorials and you have random code in your header, footer, functions files and you are bound to miss something important. If it’s something that should work regardless of the theme you are using then it most definitely should be in a plugin. That will save you both time and headaches.
Konstantin has a good point. It takes 30 seconds to update the code in your footer/header IF you remember what you did. I don’t want to dread the next WordPress update because I can’t remember how I fixed up my site after reading a tutorial, figuring it out, and pasting in the code.
I’m sorry but I don’t get it……it’s like going through rabbit holes….I don’t have all kinds of time to waste. I cannot find anything you posted here. There is no tag number one. Number two….my wordpress dashboard does not look like that. There is no editor after I click on appearance.
I meant to say there is no HEAD tag to paste the friggin code to.
Thank you so much! I hate it when all the info you get to adding something to your blog is “just add the code to the php file…” when I have no idea what they mean half the time! I tried adding the wordpress plugin for this and got a “fatal error” ooh scary, so thank you thank you, it’s working, thank you for the screen caps, that REALLY helps! (Google had said to paste the code “onto every page” you want tracked, which was really not helpful!)
EXACTLY! That’s why this post is GREAT! It tells you exactly what to do without having to know code!
If the code is in the footer, the analytics code is generated when the page fully loads. This has the effect of skewing the bounce rate to the positive. People who leave before the page is fully loaded are not counted as page visits.
There used to be an advantage in load time by putting the code in the footer. However, since the new code is asyncronous that is no longer the case.
Smartly put, a high bounce rate with low visits = poor analytics anyway
Thank you for this! It helped me A LOT!!
Just wanted to say thanks, I was having trouble with this and you explained it easily and perfectly.
There are hundreds of tutorials and websites describing similar stuff but this one is more helpful. Thank you so much for the post.
hi,
i’m using wordpress.com not wordpress.org…i know there’s different allowances for what can be done with .com or .org, so any chance you can help me out on how to install google analytics in .com? is it possible?
thanks x
I am a newcomer in web designing profession.To add site map in my site http://tempting-recipes.lv2lvu.com/
I verify my ownership of mine but can not setup Sitemap.
now i want to add google analytics,But it’s not working?what’s wrong?
Hi all
Or if you have no writing access to your themes via the editor, nor are you willing to touch your files, you can install this small plugin that is easy to use:
http://wordpress.org/extend/plugins/wp-analytics-tracking/
Try this http://wordpress.org/extend/plugins/google-analytics-client/
the yoast Google analytics plugin on my site has not been giving me any new updates for the past 2 days , yet the status on the tracking info tab say “Recieving data”.I am thinking of going manual