How to add google analytics to your wordpress blog

Adding the google analytics code to your wordpress code is very easy, just follow these steps carefully:

1. You need a google account, if you don’t have one, create your free Google Account here.

2. Sign into your google account and go to Google Analytics and click on “Add Website Profile” at the bottom of the page, make sure that “Add a Profile for a new domain “ is ticked and enter the url of the blog/ site you want to analyze and hit finish. You are now presented on the next page with a piece of code. That is your google urchin tracking code. Ok, leave this window open and open a second window in your browser.

Don’t skip the next step!!!!

3. Go to the dashboard of your blog and look for Appearance>Themes>Editor>Templates>Footer (footer.php). Back up your original footer.php by copying and pasting it in a NOTEPAD document. Don’t use word for this, as it may add additional characters to the code. Just open the humble notepad, copy and paste the footer code in your document and save it in case things go wrong. Important! Don’t skip this back-up step!!!!

4. Go back to your google account and copy your analytics code and paste it into the footer.php file, just before the last “</body>” at the end of the page, leaving the rest of the code as it is. Take care not to delete anything, you want to add code, not to remove it! Save your edit. Go to your google account and click “Finish”

Done! If you have followed all steps than you should see now your new web site profile in your google analytics account.

5. It takes some time, up to 24h, until the first data appears. Please be patient 😉

6. In case something went wrong and/ or you want to restore your original footer without the google analytic code, just open your notepad back-up document and copy and paste it into Appearance>Themes>Editor>Templates>Footer (footer.php). Take care to replace the previous code completely.

If you like this blog post and found it helpful, why not share it with your preferred social network? Handy links and bookmarklets above ^^^ 😉

41 comments to How to add google analytics to your wordpress blog

  • video game

    What template are you running on this site ? I really like it. Could you post where you got it from ?

  • hospitalera

    @video game

    Just scroll down to the footer and there you find all the information you need regarding this template 😉 SY

  • Benjamin

    Thanks for this interesting post. Helped me to pass the time while i was hopeing the day to end at work. I will definently visit this site again.

  • hospitalera

    Glad I could be of use 😉 SY

  • cat

    Nice post! Your directions are really clear and easy to understand. Google Analytics is awesome, and every blogger should have it one their site!

  • hospitalera

    Thanks a bunch, your site looks very nice, fancy to write a guest post (do follow back links included) for me? SY

  • I just created my own Google account, so it’s good to have some guidance for my next steps.

  • hospitalera

    Good luck with your endeavors, your site looks very nice and professional! SY

  • Deniel

    I think that is even easy as compared to install a plugin to do this. Although I always reluctant to interfere any coding files but I think it is very easy to implement. I’ll be doing it right away.

  • Shower Enclosures

    Great topic I have just started with google rankings so any help understanding this is welcome..

    Jill xx

  • thanks for giving the step about if something went wrong because that definitely did happen to me. I was glad that you put some troubleshooting tips at the end, just in case I didn’t follow the directions correctly.

  • Thanks..I actually started to use Google Analytics when I saw your posting…

    Not a tech savvy person and all this plugging in makes me nervous..

    I wonder though will I leak too much private data to Google using all their services..I already using Google Gmail, Adsense, Webmaster tool…and now Google Analytics… Oh mine..

  • cool! It would be nice to easily access my google analytics account right from my WP. Thanks for sharing!

  • hospitalera

    @Phoebe Have a look here to get really scared!

    @Hire a Geek
    What would be the advantage? Perhaps if you only have one site, but if you have many, it would be to time consuming. SY

  • […] is easy! Any questions? Just ask! Related Posts:Adsense NicheAlternative to domain or cash parkingHow to add google analytics to your wordpress blog Share this on del.icio.usDigg this!Share this on RedditStumble upon something good? Share it on […]

  • WOW this is great! I was getting so tired of switching between the wordpress screen and the google analytics tab in my browser! THANK YOU THANK YOU THANK YOU THANK YOU!!!!!

  • hospitalera

    @Travis healthy green lifestyle
    You are welcome, but you will still need to go to Google Analytics to check your stats 😉 SY

  • Jack

    I recently started a blog and it’s a little overwhelming at times. Information like this is very useful, it helps me understand what to do and how to improve. Thanks.

  • hospitalera

    You are welcome, feel free to show us your blog when it is finished and to ask any questions you might have. SY

  • This is really helpful tip thankyou very much.I always access analytics account separately.I was not aware that i can access it through wordpress admin.
    Is there something to integrate webmaster tools?

  • hospitalera

    Now you can NOT access it through the WP dashboard, this post refers to an easy way to add the Googe Analytics code to your WordPress blog, nothing else. You will still have to access your stat via the Google Analytics dashboard, SY

  • Umm wow thx I appreciate the help. I have been trying to use this for a bit now and I have had a lot of problems. This article really helped me out. Google Analytics here I come!!

  • Manie@Best Web Site Host

    You can also use the plugin “Google Analytics for WordPress”
    I like your blog, I added to my “Blog to Read List”….

  • hospitalera

    Yes, but wouldn’t that be overkill? I mean a whole plugin for such a simple task? Especially if you use a theme that has already custom fields for stats code incorporated?! SY

  • Thanks for this blog post – I always had trouble adding the google analytics! And what I like about this post is – it is easy to follow! Many thanks

  • hospitalera

    You are welcome! SY

  • bully

    What would be the advantage? Perhaps if you only have one site, but if you have many, it would be to time consuming.

    Thanks and Regards

  • hospitalera

    If you don’t know anything about your readers how can you cater for them? Google Analytics or any other analytics stats for that purpose should be standard for everybody that takes SEO seriously! SY

  • Justin Wright

    Great tutorial! I was looking for some simple directions to send off to a client and this worked great.

  • hospitalera

    @Justin Wright
    I only hope you respected my copyright and credited me, at least with a link to the original text! SY

  • Neil

    I’ve just wired up my site wiht Google Analytics and was struggling as I’m not into I.T. This helps. Thanks.

  • Gustavo

    Must we place the code on the footer or can we place it on the header also?

  • hospitalera

    That is the reason why you always should make a back-up before changing things, glad my post was useful, SY

    The code has to go before the last body tag, that excudes the header area, SY

  • cortney

    Footers are the worst, if you don’t backup you might as well call it a day. If something goes wrong just take the whole code out and start over.

  • hospitalera

    @ cortney
    Never neglect to back up! SY

  • For the people who are asking about why bloggers might use certain analytic plugins such as Ultimate Google Analytics (one of the most popular ones). It’s because the plugins provide additional ways to customize what information is sent to Google Analytics.

    They don’t necessarily provide MORE information, but they can make it easier to analyze specific data from Google Analytics so that you can easily focus on areas of interest that are most relevant to your particular situation/business/blog.

  • hospitalera

    Thanks for the input! SY

  • Dave

    Really good instructions. Clear and concise. I have started to use a plugin now, but all my older sites (which I can’t be bothered going back to change) used this code placement and it works perfectly.

    BTW, I love the Can you guess banner idea, but would it work better if you cloaked the link?

  • There are at least a half-dozen great plugins for WordPress as well ( which let you easily add GA without having to edit your template. It can also be useful if you have multiple templates, or switch them out now and then, and dont want to accidently nuke the GA code.
    .-= Stanley@CheapWebHosting´s last blog .."Unlimited" Hosting: The Dirty Secret =-.

    • hospitalera

      Yes, you have a good point with the “multiple templates” situation, but on the other hand every plugin more slows down your site a little bit and with Google now taking page load speed into account… But to everybody what works best for him or her. SY