Great site statistics is probably the single most important success factor of any website. The best way to know your audience is through your traffic stats and this is what Google Analytics provide for FREE. In this article, we will share why Google Analytics is important, and how you can install Google Analytics in your WordPress blog.
Why is Google Analytics Important for Bloggers?
Google analytics allow you to keep track of:
Who visits your site
This part of analytics answer what is the geographical location of your audience, which browser did the user use to visit your site and many other important information such as: screen resolution, JavaScript support, Flash support, language and more.
This data is extremely useful, and it can help in numerous ways. When getting a custom design, you can use the user data to make sure that your site will be compatible with your audience. If most of your users does not have Flash support, then you should avoid adding flash element to your site. If most of your users are on 1280 screen resolutions, then make sure that your design is compatible with that resolution or smaller.
What they do when they are on your website
You can track where the user is going on your website. How long do they stay on your website, and what is the bounce rate (the percent of users exit your site on the first visit) on your site. By using this information: you can decrease the bounce rate and increase the depth of pageviews.
When they visit your website
By looking at the hottest hours in the day for your site, you can pick the time when you publish your post. If that time zone is not compatible with yours, then you can schedule your post to meet that hour.
Where did they arrive on your website from
This section of the analytics show you where did the user came from: Search Engines, Direct Links, Referral links from another site. It shows you what percentage of your visitors came from each of these sources. Google analytics also gives you the break down of each of these categories. If it is the search engine category, then it shows you which search engine got you the most traffic, google, yahoo, bing etc. It will also show you the most used search terms by visitors, so you can improve your ranking for that keyword (Check out our Must See SEO Guide for All WordPress Bloggers). The break down of referral sites show you which sites you need to work with the most. If your top referral source is twitter, then you need to have exclusive twitter content to make your twitter audience feel special. If your top referral source is an external website, then you might want to consider having a partnership with that website (link exchanges or something else).
How they interact with your site’s content
Google analytics show how your users interacted with your site’s content. It shows you what percent of the user clicked on which link on your site and much more. By seeing the user interactivity, you can work your content around your users.
By seeing the answers to the questions above, you can focus on the strategies that work for your site and eliminate the strategies that don’t work.
How to Signup with Google Analytics
First you would need to create a Google Analytics account. To do this, visit Google Analytics Signup Page.
You will see a screen like the one below. If you already have a gmail account, then use that to sign-in with. If you do not have a gmail account, then you would have to create an account for yourself.

Once you sign-in with your gmail account, you will be prompted to a screen like the one below. This is where you will signup for google analytics with your gmail account.

The third step would be to enter your site information. The fields are pretty self explanatory. You enter your Website’s URL, Account name (it can be anything that you like), Time zone country, and the time zone.

Step 4 requires you to enter your contact information.

Step 5 would require you to agree with their terms.
Step 6 is where you will receive the code to paste in your site. This is the important part of the signup. Copy and paste this code in a notepad or a HTML editor and keep this screen open.

How to Install Google Analytics in WordPress
There are 3 ways to install Google analytics in WordPress. Direct paste, functions.php, and plugins.
Plugins Method (Recommended)
There are tons of plugins available to add Google Analytics to your site. However, it is probably best to just use a simple light-weight plugin like:
Paste the Google Analytics code in the plugin’s setting page.
Direct Paste Method
Copy the code that you received in Step 6, and paste it in your theme’s footer.php right above the </body> tag.
Functions.php Method
Note: only use this if you know what you are doing.
Add the following code in your theme’s functions.php file and don’t forget to paste your Google Analytics code from Step 6 here. Before you paste it, please make sure that you have read our Beginner’s Guide to Pasting Snippets from the Web.
<?php
add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?>
// Paste your Google Analytics code from Step 6 here
<?php } ?>
Once you have installed Google Analytics in your site, you can go back to the screen from Step 6 and click Save and Finish. Then you will be taken to the overview of your site’s analytics.

You can see the status have an exclamation work. This just means that Google hasn’t realized that you have added the code to your site. It takes Google upto 12 – 24 hours to start providing you with the awesome site stats that you need.
This is a must have for every blog, so get it now. If you have any questions then feel free to ask in the comments. If you like this article, then please share it with your friends on twitter and facebook.
Note: This is only for Self-Hosted WordPress.org blogs. Free WordPress.com sites cannot use Google Analytics. Maybe it’s time to upgrade from free WordPress.com to Self-Hosted WordPress? Consider using our Free WordPress Blog Setup program.







I am new to google analytics. Today I got the code and just wanted to paste in correct place. I was wondering whether to keep in end of head section or body section. because as per google analytics instruction it was mentioned to keep in the end of head section. I am now able to successfully install google analytics. Thanks for your help.
Seems like the easiest way is to insert the script into the footer. Just did that, now I’ll wait 12-24 hours. Hope it works!
Can you set this up if WordPress hosts your blog? Do you have specific directions for that scenario?
I Am having a problem with Google Analytics, the first time i installed it i was getting correct updates, then i changed my address from http://www.green-van.com/test
to http://www.green-van.com and made a new step 6. but since then the same statistics, 3 visits and never any new ones. i am using google analitycs wp plug in now, and in my footer.php i have this
Cufon.now();
i don’t know if that is interfering with anything.
maybe i should not use the wp-plugin and do the code directly inside the footer?
can i send the footer.php or the functions.php to see if things are in the correct order?
kind regards,
Giannis
@wpbeginner That did the trick. It works now. Thank you.
@ardegas Try removing the line space in line 2.
Ok. Here is the code: http://pastebin.com/Ht1LSCr6
Remember it’s a child theme file.
@ardegas The code above works perfectly fine because all it is doing is adding an action in wp_footer to add google analytics…. the only reason why it would not work is if you paste the code in a manner which is not semantically right. Shoot over an email with your functions.php file code using pastebin or similar service… will evaluate and let you know what is wrong.
@wpbeginner I’m using a child theme, and functions.php is almost blank. The only function I have now is an empty function: <code><?php function twentyten_posted_on() { } ?></code>. I use this function to remove some metadata from my theme. Without the php tags this function won’t work. So it looks I’m using the right semantics. I’m pulling my hairs right now.
@ardegas You need to make sure that you are using the write semantics… For example you probably do not need the first <?php code because often functions.php files are already in php… So make sure that you are not opening the php tag if it is already open or closing it when it should be opened….
I tried to insert the Analytics code using functions.php, but it gave me this error:
<i>Warning: Cannot modify header information – headers already sent…</i>. I couldn’t even log in after. I ended removing this offending code from the file manager. It was bad. It’s a pity, because this snippet of code looks beautiful. I tried to remove any offending white space, but it was of no use, and now I’m afraid to even touch the functions.php file again.
The dashboard will not save the snippet. I have tried placing it just about </body> and also above the wp_footer tag (the note says you shouldn’tt seperate this from the close body tag) Still NOT saving the code.
@martinfarr1 The footer.php is located in your theme’s folder which can be found /wp-content/themes/your-theme-name/
If you really don’t have a clue, then try one of the Google Analytics plugin for WordPress.
where do i find footer.php? Have been trying to do this for days but am a total beginner I’m afraid!
@BrianBraker That is because you pasted the other PHP codes without opening the php tag.<?php add_action(‘wp_footer’, ‘add_googleanalytics’); function add_googleanalytics() { ?> <script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24076071-1']); _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> <?php }
//Here you can paste all the other codes
?>
Did not work. Completely screwed up the function.php file so site did not load. Uploaded back up file.There is a bunch of other code in function.php file
Here it is:
<?php add_action(‘wp_footer’, ‘add_googleanalytics’); function add_googleanalytics() { ?> <script type=”text/javascript”> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-24076071-1']); _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> require_once(TEMPLATEPATH . ‘/epanel/custom_functions.php’); require_once(TEMPLATEPATH . ‘/includes/functions/comments.php’); require_once(TEMPLATEPATH . ‘/includes/functions/sidebars.php’); load_theme_textdomain(‘StudioBlue’,get_template_directory().’/lang’); require_once(TEMPLATEPATH . ‘/epanel/options_studioblue.php’); require_once(TEMPLATEPATH . ‘/epanel/core_functions.php’); require_once(TEMPLATEPATH . ‘/epanel/post_thumbnails_studioblue.php’); $wp_ver = substr($GLOBALS['wp_version'],0,3); if ($wp_ver >= 2.8) include(TEMPLATEPATH . ‘/includes/widgets.php’); global $shortname; if (get_option($shortname.’_enable_dropdowns’) <> ‘false’) { update_option($shortname.’_enable_dropdowns’,'false’); }; ?>
@luxdesign28 Yes, Google Analyticator plugin does the job.http://wordpress.org/extend/plugins/google-analyticator/
Hi there,
Is a method or a plugin how to show the data delivered by Google Anlalytic directly on wordpress, without going to Google Analytics webpage ?
How to install the same in a subdomain take for example i have a website http://www.xyz.com and i want to track my subdomain http://www.123.xyz.com what should be done in-order to do so ?
Add a separate tracker.
It Allows usage of custom variables in Google Analytics to track meta data on pages. Thanks for your support will try soon.
Was trying to figure out how to install Analytics on WordPress but didn’t manage on my own.
Thanks to your info – I now managed and GA is up and running.
Just what i was after. I just placed it in the footer. Seems like the easiest option to me.
Thanks for the information. This is good advice for the beginner and seasoned blogger.
Many thanks
hello,
I am using the free wordpress version. Where do I find this part – “theme’s footer.php right above the tag”, so that I can simply copy and paste?
Thank you!
You can’t add this in your WordPress.com account. That is why they offer you with their own statistics.
You can use the same code for the meta robots? in this way:
add_action(‘wp_head’, ‘insert_meta_robots’);
function insert_meta_robots() {
?>
<?php
}
Analytics doesn’t work past the first page of my WP blog unless I add the code in my footer AND the sidebar.
This is somewhat of a disaster! I added the code and now I can’t access my blog, it’s completely whited out
Parse error: syntax error, unexpected $end in /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php on line 344
I saw this error message after I pasted the code in my funtions.php:
Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php:21) in /home3/sulukuc1/public_html/wp-content/themes/constructor/libs/Constructor/Admin.php on line 31
Warning: Cannot modify header information – headers already sent by (output started at /home3/sulukuc1/public_html/wp-content/themes/constructor/functions.php:21) in /home3/sulukuc1/public_html/wp-admin/theme-editor.php on line 89
Please help!!!!!!!
You need to make sure that the code is semantically right … meaning that opening PHP tag may or may not need to be there if the PHP is already open.
I’ve read in the Thesis forums that the new GA code is asynchronous and needs to go in the header to work properly. It also doesn’t affect page load like the old code.
Hello again, sorry my bad. I fixed it!
Hello,
When I put the Google Analtyics code in the footer.php and in the functions.php my whole blog dissapeared! Total white-out! What happened? What can I do to get it back?
so if I use a free wordpress blog I can NOT use this plug-in?
Thats correct. If you are on free WordPress.com then you don’t get this. You however get to use WordPress.com Stats.
Thanks for this, I’d just pasted it into the head.
A function is so much neater though!
Dan
Hello,
Almost, but not quite there, I would like the first option of copy and pasting the code- but, I cannot find the “theme’s footer.php right above the tag” – not in tools, settings, themes, general, etc etc. Sorry to ask its probably simple! I added it to the normal ‘text’ widget works for all else but this.
That is because you are using WordPress.com <<
Thanks. I am just beginning to understand all of the great features that Analytics can offer.
Great compilation of what a beginner needs to know about Google Analytics and WordPress! I scheduled 1 hour to find out how to setup Analytics for my new site, I was done in 5 minutes… – Thank you!
Magnificent tutorial, thanks. I’m in the 12 – 24 waiting period to see if it works but I already appreciate you instructions and your willingness to reply to comments. I actually found what I was looking for in one of your responses to a poster.
I really can not make sense of Google analytic. I prefer to use Piwik instead.
this was very usefull, i had a little trouble because i’m not familiar with the html edition this worked great for me
THNX A LOT!
Thanks for the tip, I did the copy and paste and it worked great.
Thanks for the good info.
Any differences/advantages between the direct paste and functions.php methods? Thanks!
There is no advantage or disadvantage… it’s a matter of personal preference.
Great, clear description – even for someone is a codaphobe. Thanks. I am wondering tho, if when google activates this if the stats will appear in the wordpress dashboard like my other stats package did (the wordpress.com stats) which seems to be broken as of today. Thanks!
There are some advanced Google Analytics plugin that does that, but we recommend that you check on Google Analytics site, to get the full report. Because no plugin gives full integration.
This is indeed an informative site.It was really helpfull.
I am not able to figure out still, how do you edit the footer (or header for that matter) of the theme of the webpage?
can you please give instructions where can I find way to edit my footer?
I have tried ‘Edit CSS’, ‘Extras’, and also some other options in the ‘Theme’ menu. Couldn’t get it done.
Please help.
You will need to click on appearance and then editor. Find header.php or footer.php to edit those files.
I’m thinking about going the plugin route – do I need to use both plugins or one or the other?
I know that the “Google Analytics for WordPress” asks me where I want to embed it but then then “Google Analyticar” doesn’t ask anything about embedding so I’m wondering if it does it or if I have to do something manually…
Thanks for this walk through!!!
You need the manual code or the plugin… not both. Google Analyticar just adds the code in your site.. It does not give you an option of where to embed.
I am attempting to use the Google Analytics for WordPress plugin to add the code to my wordpress site. It gives an option for installing the code in the header. When I look at my header file after activating and authenticating the plugin, I see no added code in my header file. Is there somewhere else the code is installed besides the header for my theme?
It should add it in the area, but it will not modify your theme. If the code is not showing in your theme, then it can mean that your theme does not have a wp_head(); hook in the header.php.
Step 5 states to paste the code above the body end tag. Google has changed it since. It goes above the head. Just to let you know.
Jan
Google has not changed anything… All companies would like to have their scripts added in the header << But it is not wise for the webmaster. Any smart webmaster / developer would keep scripts like analytics in the footer to speed up the load time…
WPBeginner has the codes in the footer. Twitter.com has the code in the footer and many other sites as well.
Ok… apparently the commenting system doesn’t like angle brackets. That second paragraph should have said:
If you want more accurate analytics you will use the new snippet version and you will put it in the head. If you are paranoid about page load times you will put it just before the close body tag.
How does the placement reflect accuracy? Whether you put the script in the head, or at the end…. upon the full page load, it will still count one user…
i wish i had seen this tutorial before i spent three hours trying to figure it out on my own.
Would love to know your thoughts on which method you recommend for installation. Such as are there advantages to placing the code by hand vs. using a plugin?
Using a plugin is adding multiple database queries that you don’t need. By hand is probably the easiest method and it is efficient for the site
This is one of the few features I did use a plugin for, even though it can definitely be achieved manually be pasting the code as you explained, thanks for sharing.
I just switched over from an entirely hand-compiled website to one using wordpress. This will be most helpful. Thank you!
Great tips for a newbie like me i will certainly try it now. The beauty of WPress is that it has a very little limitation.