How to Install Google Analytics on Your WordPress Blog

151 Comments

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.

Google Analytics - Step 1 Small

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.Google Analytics - Step 2 Big

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:

Google Analytics - Step 3 Small

(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:

Google Analytics Step 4 Small

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.

151 thoughts on “How to Install Google Analytics on Your WordPress Blog

  1. Hello! Thanks for publishing such a nice set of instructions! I am using the Blix theme and it doesn’t seem to have a “Theme Editor” option and I was wondering if you could help me get around this?

    Thanks,

    Victoria

  2. Hey I am not able to see the “Presentation > Theme Editor >” on my wordpress blog. All options I have under Presentation are Themes, Widgets, Extras and Edit CSS. Can anyone help me with this. I want to add analytics script to my wordpress blog to get the stats.

  3. Oh, I see. You have a WordPress.com website. The above instructions are meant for someone running a WordPress site on their own.

    I don’t know exactly how to set Analytics up on a WordPress.com site. I just tried playing with it, no luck. I’ll see what I can find out.

    Does anyone else have an idea?

  4. Pingback: Get Reviews of WordPress Plugins, Plus Tutorials at the Theme Playground | RockinThemes.com | Free WordPress Themes | Free WordPress Templates

  5. Thanks Alot, I knew it was something simple, yet just couldnt understand how to get there. Nice simple laid out help.

    Cheers Bro.

  6. Thanks for the info. We just transferred our blog from Blogspot to WordPress and I had no idea where to put the Google Analytics code. I knew the answer would be on the internet somewhere.

  7. Hi, great tutorial. I am new to wordpress and trying to install the google analytics code. Having the following problem:

    I have no idea how to get to the point where I can edit the footer.php file from my admin area.

    When I go to presentation, then theme, there is no where to edit the footer??

    Any help would be appreciated.

    thanks!

  8. Nice article, but unless you’re implementing a plugin, why not use an existing plugin to do this? WordPress Reports will insert Google Analytics code for you and give you some overview reports from their API within your WordPress control panel. And it will also show your FeedBurner stats if you choose.

    If you don’t want the reporting feature (why not?), you can use the Google Analyticator plugin to insert the analytics code, including for outbound link tracking, for you.

  9. Pingback: google » Theme Playground | How to Install Google Analytics on Your Wordpress Blog

  10. Good post. I recommend putting the Analytics code into a widget rather than editing your footer.

    That way if (when 🙂 ) you change your theme, you don’t have to move all your stats codes, the widget will migrate them all for you.

    Happy blogging,

    WordPress Ninja

  11. Pingback: 24HRKNIGHT.COM |How To Build Custom Furniture » Blog Archive » wow!

  12. Thank you! Your instructions are clear and easy to follow. Google analytics is now gathering data, and in a matter of minutes you solved a problem I could not figure out in a couple hours. Your willingness to share this great content is truly apprciated!

  13. Pingback: Kenjun TechBits » Blog Archive » WordPress and Google Analytics

  14. Thanks so much for this excellent tutorial. And to everyone who posted suggestions for widgeets etc. My question is as follows: Can I do more detailed tracking from withing wordpress, and across multiple sites that include wordpress sites? To be more specific, I am looking to track email submissions on a separate site (which I guess I could track through wordpress because the successful signup page is on wordpress), then track whether they are opening the newsletter they signed up for, and then link the original traffic or campaign source (and purchase value) to the actual product purchases they make by following links in the newsletter to a purchase form being hosted on totally different enterprise software app…..gads, sounds complicated…any help appreciated.

  15. i dont understand how to put the google analytics code in word press blog.

    when i m going to dashboard – Presentation > Theme Editor

    But i cant find Theme Editor option in wordpress blog.

    Please let me know how to put the google analytics code in word press blog.

    Please give me perfect guidelines for blog

  16. Pingback: What Can Google Analytics Give Me ? » Tech At Hand

  17. Hy,

    I have a problem with my wordpress theme. Footer.php looks…strange and I cannot find .
    This is my footer.php data:
    “”

    Can you, please, help me?

    10x

  18. Hello,

    Thanks for the great instructions, really made it simple to follow and complete.

    Thanks again, will be checking rest of site to see what other good posts you have.

    Regards
    Mike
    lasventions.com/specials

  19. Great tutorial. I really helped a lot…
    One question, though…
    Wouldn’t it be easier to paste to code on an untitled Text/HTML widget on a sidebar (that is always present on every page across the entire site) then to edit the footer code?
    Just a thought…

    Thanks for the tut

    Leo

  20. Hello,

    I have installed Analystics in the footer with no problems. I’ve heard though that if you install it in the header you receive more visits… do you have any information on that? Thanks.

  21. Thankee, thankee, thankee!
    I’ve been trying to figure this out for several hours until I found your blog on google.

    It only took about 10 min. after I saw this.

    Thanks again
    Duane

  22. Im having some trouble…

    I input the tracking code in the footer.php file, before the body tag. But when I got to Google Analytics to “check status”, I get a message saying the code isnt installed.

    I tried using both codes (legacy & new tracking) and both bring back the same responds.

    Whats going on?

  23. Pingback: casino jeu

  24. Hi your tutorial on how to install Google Analytics is clear but my template is bluebusiness and I cannot seem to update the footer.php file – can you tell me where else i can install the code on this template please? Thanks

  25. Thanks for the instructions on how to install Google analytics on WordPress.
    It is a breeze with your instructions. Perfect !

    James Hau

  26. I read and appreciate your instructions, which seem clear enough. I am not successful though…yet. Is there something I’m missing? Don’t have a footer. After putting it in a side widget, the script erases, b/c java script is not allowed. Did I miss something?

  27. Thanks for the help – in understandable language. Only thing I struggled with was finding presentation on my dashboard – on mine I had to use design. It was easy up to then and I easily installed it once I’d worked this out, I’m now up and running.

  28. Pingback: How To Track WordPress Comments & RSS In Analytics » Branding Rant

  29. Pingback: How To Track WordPress Comments & RSS In Analytics » Branding Rant

  30. Thanks! I had some trouble locating “Presentation”, but I read above in the comments about looking under “Design”, and I found what I needed.

    Thanks for these… Great instructions!

  31. hi,
    unfortunately, after I paste the code in the footer, I have no option to save or update what i’ve just done. it actaully says right there mocking me: “If this file were writable you could edit it”.my theme is caled greening if that counts for anything. do you have any advise for me? i’m such a newbe.
    thanks.

  32. I’ve checked out the footer.php file for two different themes I’m using on two different blogs. Both (unexplainably) don’t have a tag. Just a closing tag.

    But my question is, why not just put the code in header.php instead of footer.php?

  33. How you think when the economic crisis will end? I wish to make statistics of independent opinions!

  34. 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?

  35. 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?

  36. 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

  37. 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.

    • 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.

  38. 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.

  39. 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

  40. 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

  41. 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.

    • 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.

  42. Pingback: Why ALL Online Artists and Art Bloggers Should Use Google Analytics

  43. 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.

    • 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 🙂

  44. 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.

  45. 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.

  46. “body” tag, written with the arrow point out on each side and the slash before. this blog keeps cutting out code.

  47. 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!

    • 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.

  48. 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.

  49. Pingback: TopDailyBlog - » How to Add Google Analytics to WordPress

  50. 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.

    • 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.

  51. 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

  52. 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?

  53. 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!

  54. 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

  55. 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..

  56. 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?

  57. 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?

  58. @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. 😉

  59. 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

  60. 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.

  61. 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.

    • Hmm, maybe I should change my ip info in Google Analtyics, before I start working on my site each time.

      Thanks a lot.

    • John, I’ve read your comments on Ryan Imei’s post concerning google analytics. You seem to be very knowledgeable. I am new to wordpress, and I am only dabbling to help a friend’s post. While trying to load GA, I only get an option to edit css. There is nothing to the right of it as mentioned. Every suggestion made in the post does not help me. Someone mentioned using a text box. Would that have to go on every page? Will the text show on the site? I’d like to install this as clean as possible but I’m having tremendous difficulty getting around the lack of a theme editor option. Could you please advise? What started as a favor is turning into a hassle.

  62. 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!

  63. Pingback: Googles Analytics for WordPress | iliveontheweb.com

  64. Thanks for the detailed instructions. However, I am using the theme “Black Circle” and when I view footer.php there is just a series of numbers and letters ( basically cr*p) – when I select a classic theme from WP , the correct code can be identified. Any ideas ?

  65. Hi Ryan, thank you for the useful tutorial. I forgot putting Google analytics code in my blog so it is not recorded in the analytics. But, unfortunately I don’t find the menu of Presentation. I use the version 2.7 Would you show me where it is ? Thank you again for the information you share.

  66. I’m using the Vigilance theme. When I go to the dashboard, I can’t seem to find the “footer.php” link to paste the code in.

    Can you help me?

  67. Hi Ryan thanks for the advice, I’m using Press Row on WordPress and I can’t find my footer.php. I tried adding a text widget with the code for Google Analytics, but it just showed up as code on preview. Any suggestions?

  68. Thank you so much for creating this tutorial.

    Your post is easy to read and concise.

    With your tutorial, I was able to easily add the Google Analytic tracker to my blog.

  69. Howdy,

    Just wanted to drop you a line and thank you for a great post. Yes – it’s may not be the only one “out there” about how to add GA to a footer.php file – but it’s great that you’ve taken the time to write it – and even added screenshots to it.
    Hope you get lots of traffic from it as a result!
    Cheers,

    Guacira

  70. Thanks for this. I was following the directions from Goggle and they were telling me put it in the index.php file. Seems to work now that I stuck it in the footer. Thanks again. Good instructions.

  71. I am using WordPress and my Dashboard has an Appearance menu but then the options under it are Widgets | Extras | Colour Options | Typekit Fonts | Edit CSS. None of these seem to work to get able to post the code from Google Analytics. I tried adding a new text widget into the Andreas theme but it just showed the text of the Google code.

  72. I’m having difficulty in figuring out how to paste the code into my WordPress blog – I’m using Andreas09 as my theme. Any suggestions?
    Many thanks
    John

  73. Hi Ryan, I hope you’re still checking this. I have a wordpress blog running the Vigilance theme. I’ve tried copying both the new tracking code and the legacy tracking code into a sidebar text widget.

    No luck.

    It’ll paste, and then on saving, it’ll delete all the ‘code’ parts of the text rendering it useless.

    Any suggestions?

  74. Adding to the “Thanks” for these instructions.
    I’m having a problem mentioned in the discussion but not finding a solution . . . My footer.php does not seem to have a body. Begins:
    “”
    Advice?
    Thanks!

  75. Thank you so much Ryan! I am absolutely not a programmer and these instructions were straightforward and extremely easy to follow. The humor made the article actually entertaining – and will have me come back to your site for future technical help. Thank you so much!

  76. I don’t see footer.php. I’m using this theme: Ambiru by Phu Ly. Can you please suggest how else to do it?

    Thank you!

  77. Brilliant clear instructions – thank you. Being a newbie to programming my own wordpress blog, this was easy to follow. Your site will definitely be bookmarked. Now to work out how to make my gravatar appear in the tab at the top of the page. 🙂

  78. Hello, I login to my WordPress blog at http://www.wordpress.COM, rather than http://www.wordpress.ORG. I’ve read all over the internet that if you’re using a .com wordpress account, then you can’t use Analytics. My blog is NOT self-hosted (it’s hosted through wordpress, domain is through GoDaddy). I do not have the option to edit my template and when I tried the other option of pasting the code into a Text Widget, the text shows up on the blog, which I don’t like. Is there a way to make it hidden? Please help!

  79. I am not able to figure out where to place my analytics code. I was able to do it in blogger easily but haven’t figured it out with word press yet.
    Thanks,
    Jared

  80. Hello, I am using WP theme Blass and I can’t find a body tag in my footer.php. Can you help? I’d thought I’d updated with the UA code, but analytics is only tracking the old archived site.
    Thanks much for your help!

  81. Is anyone familiar with the Ultimate Google Analytics plugin for wordpress? Does anyone know if it works or how long it takes for google analytics to recognize that you have added the correct code? Thanks.

  82. I have the exact same problem as Corinna mentioned. Can you please help me how to find the place where i should put my code? I managed to do it on blogger but not wordpress.

    Thanks Lisa. 🙂

  83. Hello!

    I have the exact same problem as Corinna mentioned earlier and I tried the text widget thing too. I really don’t know where I should paste my code. I hope you can tell me where I can put my code.
    Thanks a lot, Lisa.

  84. Thank you so much. I’ve been trying to install this forever. I finally figured out where to put the code thanks to you. I really appreciate your help.

  85. How do you set up two different website accounts in wordpress for google analytics? I already have one website I am tracking and now I need to set up another website (our blog) for tracking. Do I need to set up another google analytics account with a different email? I am very frustrated and don’t know how to do this. Any feedback would be really appreciated!

  86. I’m using the Chunk theme and can’t find the path to posting the google analytics. There is no header.php or footer.php. How do I insert the code so that I can use Google Analytics.

Comments are closed.