How to Install Google Analytics on Your Wordpress Blog
As Theme Playground approaches the end of its first week online I decided it would be a good idea to set up Google Analytics to track the stats. And it seems only fitting that we take this opportunity to, together, walk through the steps of setting up Google Analytics on a Wordpress blog.
Google Ana-what?
Google Analytics is the mega-giant Google’s version of stat-tracking. They are also, arguably, the best available.
Google Analytics is a free service offered by Google that generates detailed statistics about the visitors to a website…Most important, a webmaster can define and track conversions, or goals. Goals might include sales, lead generation, viewing a specific page, or downloading a particular file. By using this tool, marketers can determine which ads are performing, and which are not, as well as find unexpected sources of quality visitors.
Just to give a taste of what we’re talking about.
I have, honestly, never used Google Analytics before. In the past I’ve tried other stats tracking plugins for Wordpress (not to mention Wordpress.com’s official stats plugin earlier this week) but nothing ever worked out. So, on to the big boys.
Let’s install it already.
First Things First
Do you have a Google account of some sort? You will need one. That’s okay if you don’t, you can grab one during the process.
Hit up the following link: http://www.google.com/analytics
Now is the time to sign in. Look to the box on the right. If you don’t have a Google account, you will be prompted to sign up now. Do it.
I’ve signed in with my info above. And don’t both trying to get in, it’s hopeless :).
If this is your first time stepping into Google Analytics (which it probably is) then you’ll see a screen prompting you to enter the information for the website you are wanting to track. If you don’t have a website…well…um…why set up an analytics account?
Seriously. Why bother?
So assuming you have a website, throw the address in there with all the information it asks for.![]()
Next it will want your name (no cheating) and number, same as any first date would expect. Again, throw all the info they want into the boxes and hit Next.
Finally, make the Google lawyers happy by agreeing to their terms of service. I would tell you what is written there, but I have no idea. Who actually reads that stuff anyway?
Create New Account. Done and done.
Well, not quite.
Plugging into Wordpress
A brand new screen should be showing, prompting you to drop a set of code into the footer of your website pages. It should look something like this:
(Click above for a larger view)
This is where having a Wordpress blog makes life easier. Google wants to converse with your website (just like you’ve asked it to) but needs a certain Javascript code to be at the bottom of every page of your web site. If your site is static, this can be a pain, or at least an annoyance. But since we’re using Wordpress, and everything is dynamic, we only have to copy and paste once.
Log into your dashboard (preferably in a new window) and browse to Presentation > Theme Editor > footer.php.
Note: This is assuming that you are using a fairly standard Wordpress theme which uses footer.php as the final template of a page. If this is not how your blog is set up and you can’t figure out where to go, post a question in the comments to this post.
Take your Google Analytics code and paste it into your footer.php file in Wordpress. It shouldn’t be all that important where the file goes as long as it comes before the ending body tag. In other words, just put your GA code where I indicate in the following screen:
Of course hit Update File. As far as Wordpress activity goes, you’re set! Nice work.
Check Status and Analytic Stats
A nice big button on your Google Analytics homepage should say Check Status. You’ll want to click that so Google can start communicating with your website.
Now all you have to do is bookmark Google Analytics and keep an eye out. Of course it will take a few days before any stats start showing up. Believe me, I know. The stats for this site are still in the collection stage.
Whatever you do, don’t get into the habit of checking your stats every 5 minutes or else…oh, hey, sorry I have to go…yeah, you know.
Note: Having problems? Post a comment below and I’ll see what I can do.
Did you enjoy this post? Then it might be worth your time to subscribe via RSS using your Feedreader or, if you prefer, via email.





107 comments so far
Scott said:
Hello and thank you for the great instructions. The comments are a worthy read as well! I installed the google analytics tracking code to my footer.php at my website, but I am now interested in the code to avoid tracking admin hits on the site. This would really help to make my stat tracking data more reliable. I know I have seen that code floating around somewhere… but where?
ANN QUIAZON said:
i’m fairly new to blogging and i’m at a lost among all the codes.
i was trying to paste the google analytic codes to the footer.php just like you said but changes can only be made if i make the page rewritable. When I checked the codex blah blah i really think its such a hassle,i might get lost the more,please help.
is there a way to do it without all the hassles?
SteveB said:
I like to track clicks on links on the page, I don’t think you will get that pasting to footer directly. Also, to Scott above.. To stop admin hits in Google Analytics, create a filter (in analytics) that will ignore your ip.
Steve
Tizmanian said:
Perfect instructions! Thanks dude.
Ronin said:
Im new to GA and need to a reference for installing it on WP.
Great and thanks for posting.
Daniel Howard said:
Hi thanks for the step by step method of putting this to work
Thanks again
Danny
Michael Podgoetsky said:
Hi Ryan thank you for this advise. But I just updated the Word Press Blog and this is the latest, I think 2.71 , would your way of doing code installation work for the latest version?
thanks
Michael.
Ryan Imel said:
Hey Michael, thanks for reading. Despite the update in WP since this was written, it should absolutely work with 2.7. I’ve used a method like this for every version of WordPress since 2.0.
You can also try putting the Analytics code into a sidebar widget, which might be slightly easier than digging into the theme.
Joanne said:
Hi Ryan,
We have a wordpress blog for our business. The blog stats are really limited and I can’t really get the kind of tracking info I need. I saw your article about how to install Google analytics on your wordpress blog and thought I’d try it, but I’m not seeing a Theme Editor>footer.php option. This is the link to our blog:
http://soundviewsummary.wordpress.com/
I’m not sure if the version we’re using even has editing area this available. Hope you can help! Thanks.
Carlo Duncan said:
Dear Ryan,
I am unable to find Presentation > Theme Editor > footer.php in my theme which is Vigilance. Can you help me, or must I change theme in order to apply GAnalytics?
Thanks
Carlo
awakr.wordpress.com
Pat Alb said:
Hey Ryan, I thought I was saved from the tech world when I saw this nice info but I think I have a diff setup. I followed your instructions and went to dashboard, appearance, themes & editor and landed on Stylesheet (sheet,css).
Do you have any suggestions how I can add the google analytics and adsense codes into my wordpress? Thanks in advance, i think you’ll do very well on this site!! G.L. - Pat
Scott Summit said:
Ryan, thank you for taking out the time to create this tutorial.
We are using Wordpress 2.7.1 and our blog lives on a subdomain.
Right now the Google Analytics and Quantcast code is on the main page of the blog. If you click through to the URL with the entire post, the tracking codes are not included on the pages with the individual posts. Any help will be appreciated.
Thank you for your time.
Ryan Imel said:
Hey Scott, hope I can help. If you place the Analytics code into a new text widget that is on a sidebar that is on every page of your site, that should fix your problem.
If that doesn’t sound right for you, then give me a ring on the contact form, and maybe getting some more specifics on your situation I can help better.
John Hoff - WpBlogHost said:
Hi Ryan, great tutorial - I’m always on the lookout for WordPress sites.
@Pat Alb - When you click on the Editor, the stylesheet is typically the first file you land on. Over on the right you should see a list of files, one of them should be your footer.php file. Click on that, paste in your code, and click “Update.”
@Joanne - Log into WordPress and you should arrive on your Dashboard. Over on the left you should see a menu called “Appearance”, click that, then click “Editor”. From there, follow what I mentioned to Pat just above your comment.
Ryan Imel said:
Hey John, thanks for helping out here. I’ve been meaning to update this tutorial with a screencast, but won’t have time for that until next week. Can’t ask for more than one commenter helping another, though
John Hoff - WpBlogHost said:
We’re all here to help each other. I know what you mean about time - there’s never enough.
Ryan Imel said:
Definitely. Just let me know if there is anything I can do for you, John!
foodie said:
Thanks for the tut dude. It went off without a hitch except for the difference in menu options with the new wordpress version. Fortunately I’m familiar enough with the interface that I figured it out before seeing the comments. Now to wait 24 hours and see if it worked…
I really appreciate the time you took to post this.
Steven Vilendrer said:
Please help! I’m trying to install the analytics tracker but the website pages have no tag anywhere. I’m working with PHP code in Dreamweaver and trying to install this for my boss. Could someone please help? Thanks.
foodie said:
Please be more specific, so we can help you.
Steven Vilendrer said:
that is no tag anywhere.
Steven Vilendrer said:
“body” tag, written with the arrow point out on each side and the slash before. this blog keeps cutting out code.
Raul said:
Thanks for the easy tutorial, unfortunately it’s not working for me. I’ve pasted the new google analytics code immediately about the in footer.php. I can see by “view source” that the code is there, but Google does not see my tracking as being installed.
Any ideas, and thanks!
Raul said:
Fixed…
Well, I seem to have resolved it. Google provides this code:
try {
var pageTracker = _gat._getTracker(”whatever”);
pageTracker._trackPageview();
} catch(err) {}
but in the help refers to the same code without the error trapping. I removed the try / catch bits and it’s hooked up now. Off to tell google, I guess.
M Rahman said:
Thank you so much . It is a very useful tips. But I just updated the Word Press Blog and this is the latest, I think 2.71 , would your way of doing code installation work for the latest version?I really appreciate the time you took to post this.
tom benedek said:
Hi:
I am using chaostheory and cannot figure out how to add the google analytics to the footer. Thanks for you help.
Tom
tom benedek said:
I am using Chaostheory theme and cannot figure out where to past the text from google analytics. On appearance-theme i cannot find footer!
Thanks,
Tom B.
Raul said:
You could always grab the file from your server (SCP or FTP), edit it manually and restore it. Or, if your provider allows shell access, just manually edit on the server with, say nano (or if you are Linux guy, vi, but I’m not sure you would have asked in that case).
Good luck.
Eight Women Dream said:
THAN YOU FOR THIS! This has been a problem for me and your instructions are great. This fixed the problem I was having getting my Google Analytics stats. Now I will finally be able to run my reports.
Catherine
Jayvardhan Patil said:
yes you can also do like this
Adding Google Analytics to WordPress blog (for newbies)
http://codeforfuture.com/2009/03/13/adding-google-analytics-to-wordpress-blog-for-new-bies/
Justyn said:
I like your post about Google Analytics, but what was it about the official Wordpress Stats plugin that “didn’t work”?
I have been using it for about a year or two on my blog and hasn’t failed me yet, I’ve never seen the reason to switch.
You said in regards to Wordpress stats plugin “I would still suggest ditching the plugin because it isn’t locally hosted.” but isn’t Google Analytics hosted by Google, or is it run locally on your server?
Bunny Smedley said:
I have a Wordpress blog, using the PressRow theme, and am trying to add Google Analytics. Your instructions look admirably simple, but when I browse to ‘presentation’ in my Dashboard I can’t find ‘theme editor’ anywhere.
Sorry if this is a really silly question, but can you please help me figure out where the code goes, using PressRow (you gave it a good review so I assume it doesn’t somehow block Google Analytics?)
Thanks!
Sid said:
Hey man thanx for the great advice.
The thing is, I don’t have any theme editor in my dashboard. So ‘im wandering if the problem is my theme that doesn’t allow me to play in the editor. Do you have any suggestions??
thank you very much
javier javier said:
Hey, i get this message on the bottom of my site
T_CONSTANT_ENCAPSED_STRING in /home/content/j/a/b/jabaez02/html/wp-content/themes/german-newspaper/footer.php on line 60
what the hell is it? How can i fix it?
Thank you..
Pat said:
Thanks, very simple and easy to follow instructions. really helpful.
Dan Irwin said:
I am brand new to coding and wp. When I go to my footer.php template, there is no code…just hundreds of lines of gobbledy-gook running together (theme is travel 3). I added the code after this, then added:
But GA is not seeing it. There is no other real code on the page, except <? at the top.
Can you help?
Topangadan said:
My footer has no recognizable code…just hundreds of lines of gobbledy gook. No php anywhere to be seen. I added the code to the bottom of this, but it had no effect. GA is still looking for me.
Any suggestions?
John Hoff - WpBlogHost said:
@Dan Irwin - looks like you got it. I went to your site and can see the code at the bottom when I view your source code.
@Topangadan - you appear to be the same person as Dan? See my reply to him above.
Apoc said:
Really useful post. Thanks!
ximi said:
hi, ryan…
I have put the script on my pages, it works. It’s a great tool frm google. I also installed Google Analytics Dashboard plugin into my wordpress. I have put correct email and password, but it doesn’t work. It can not “connect” to google.
Do you have any idea?
thanks
Nail said:
Thanks for the instructions, it really helped, additionally I would like to know if anyone can answer that: Is there a way to filter admin hits if I am not using static ip.
Thanks.
John Hoff - WpBlogHost said:
Nail
Even though you’re on a dynamic IP, it probably will rarely change. Go ahead and set up Google Analytics to filter your IP and if your IP ever changes, just do a quick IP change.
Nail said:
Hmm, maybe I should change my ip info in Google Analtyics, before I start working on my site each time.
Thanks a lot.
Sarah W said:
So I followed the instructions and pasted the code in the footer php section right before the body text but when I hit update file the changes dont show up/remain in the code. The analytics setting page has a tracking unknown signal and the view source code on the blog doesnt reflect the new analytics code either. Did I do something wrong? I’ve tried several times now, is that just making it worse? Please help!
Russ Wood said:
Thanks for the guide, Ryan.
I’ve put the analytics code into a text widget on my side bar and it seems to be doing the trick.
Ryan Imel said:
Glad you found it useful, Russ.
Josh Rimer said:
Awesome, thanks for making it so easy to add that to my new blog!