How to Add Google Analytics to WordPress in Under 60 Seconds

There’s no doubt Google Analytics sets the standard when it comes to gathering information on your site’s visitors.

Analytics can show where they landed on your site, what they read, how long they stayed, what they were searching, the browser they were using, where they live, their age and even their interests.

Adding Google Analytics to your site is easy. So simple, in fact, that it takes less than a minute!

For today’s Weekend WordPress Project, I’ll show you how to add Google Analytics to WordPress with very little time and effort.

Feature image
Add Google Analytics to your side in under a minute.

Featured Plugin - WordPress Facebook Plugin

Would you like to add Facebook comments, registration, 'Like' buttons and autoposting to your WP site? Well, The Ultimate Facebook plugin has got that all covered!
Find out more

1. Login to your Google Analytics Account

This tutorial assumes you’ve already signed up for Google Analytics. If you haven’t already got one, it only takes a second to sign up, especially if you’ve already got an account with Google. Head to the Google Analytics site and create a new account.

After you’ve signed up, you’ll be given a piece of Javascript code to add to your site.

Tracking code
After signing up for Google Analytics, you’ll be given some code to put in your site.

2. Add the Google Analytics Code to Your WordPress Theme

Copy the tracking code. Go to your WordPress Admin and then Appearance > Editor.

Open your theme’s header.php file and directory underneath the < body > tag, paste the tracking code. Click “Update File”.

Adding code to header
Add the tracking code directly below the < body > tag.

3. Check Analytics is Working On Your Site

Receiving data
Once you’ve insert the tracking code into your theme, your Google Analytics tracking should change.

Go back to your Google Analytics account. Click on “Admin” at the top of the page and under “Property” choose your site and then click “Tracking Info”.

If the Tracking Status is “Receiving Data,” then you’ve successfully added Google Analytics to your site.

You can now click on the “Reporting” tab at the top of the page to see your site’s analytics overview. It may take Google up to 12-24 hours to start providing you with site stats.

Featured Plugin - WordPress Google Maps Plugin

Simply insert google maps into posts, sidebars and pages - show directions, streetview, provide image overlays and do it all from a simple button and comprehensive widget.
Find out more

Or… Just Use a Plugin

If you don’t want to edit your theme files, Google Analytics + is the plugin you need.

It puts all the important statistics at your fingertips by adding beautiful charts and graphs to your dashboard and the post edit screen.

View statistics for individual posts, a site or even an entire Multisite network without having to leave your WordPress backend.

A new one-click Google login process allows easy access to your analytics. Simply add a new account ID in the network settings to start collecting data for your entire multisite network.

40 Responses

    luko_del_ponte

    Is there any reason to put it under tag? Usually it’s included through functions.php or directly before closing tag. Is there any benefits from this approach?

      Raelene Wilson
      • Post author
      • 8
      • #11547

      There are a few different ways to add tracking code to a site. This is just one of them and probably the easiest.

    toke_frostholm_rasmussen

    Nice post.

    I have just redesigned a website for a friend. He had google analytics set up and working fine. They website is made with wordpress.

    After the redesign (finished 3 days ago) google analytics are no longer coming in. Under “Status” in google analytics it says “receiving data”.

    Can i simply add the tracking code again via the plugin like you did and everything will start working again?

      Raelene Wilson
      • Post author
      • 8
      • #11547

      You’ll need to check the site for the tracking code, though if it’s not there you can log in to your friend’s Google Analytics and copy the tracking code there and paste it into the site as per my tutorial above. Good luck with it!

    j_preble

    Any benefit to putting the script in header.php over footer.php?

      scott_grodberg

      Google recommended that for the PageSpeed metric

    daryl_jackson

    Hi Raelene! Please can you help me? I followed the How to Add Google Analytic instructions and pasted the tracking code under tag but some how I have broke the site, the error that is displayed when I try to look at my site is:

    Parse error: syntax error, unexpected $end in /var/sites/g/gmbv.co.uk/public_html/wp-content/themes/parallelus-vellum/header.php on line 304

    It would be greatly appreciated if you could please help me in anyway

    Many thanks!

      Raelene Wilson
      • Post author
      • 8
      • #11547

      Hi Daryl, where did you put the tracking code in your site? You didn’t accidentally delete some other code in your site?

    sandeep_bhalla

    Not helpful at all. There is no Editor in Appearance. Only a css editor which does not open the Theme Header.
    Something outdated or missing. Hope plugin will work!

      DavidM
      • Staff
      • 7,766
      • #12

      Hey there, sounds like you might be using Multisite, where the editor is instead accessible at Network Admin > Appearance > Editor.

      If it’s just a single-site install, then it should be accessible at Appearance > Editor for any Admin user. If not, then it may be that you’ve got another plugin or code restricting access.

      Hope that helps, please feel free to ask if you have any questions! ;)

    tina_sadeghi

    I have the same issue as sandeep_bhalla, I do not have Editor in Appearance. What is our alternative? google analytics+ cost extra, where as google analytics is free.

    Anyone, know the solution or answer to this?? would really appreciate it :).. thanks

    paul_underwood

    Adding Google analytics to your WordPress site should be done with a plugin. If you change your theme Google analytics is an easy thing to miss. Keeping it in a plugin means you keep your analytics code even when you change themes.

      DavidM
      • Staff
      • 7,766
      • #12

      You’re totally right, it’s also much easier, no need to dig through theme code to find a nifty place to paste in the code.

      It’s just much simpler with a plugin. :)

    wasim_muklashy

    well this was ridiculously easy. thanks for that. it literally took me less than a minute.

    ayafoue_couassi_ble

    Thank you Raelene for telling us how to place the Google Analytics cod eon WordPress.

    kate_mather

    Hi Raelene – I did everything you said to do and have checked it over and over but it still says Status: Tracking not installed…any tips??

      DavidM
      • Staff
      • 7,766
      • #12

      Hiya @kate_mather, are you sure you’ve got the correct Analytics code pasted in and that you’re looking at the correspondig property for that code in Analytics?

      Perhaps you’re looking at a different property or have pasted in the code for a different property?

    orce_bogoeski

    I can paste the code from analytic but i can not save it, some codex shows that i don’t understand…please help..

      DavidM
      • Staff
      • 7,766
      • #12

      Hi @orce_bogoeski, sorry to hear you had trouble with that, you’ll want to be sure you’re not pasting the code within any php tags, that could cause errors.

      Ultimately, the plugin mentioned above would be the simplest way to get that added though. Then you wouldn’t need to find a place to safely paste it in your theme.

      Hope this helps. :)

        Lauren

        Hi,
        I’ve triple checked now that I’ve done everything correctly in the instructions, yet my Analytics Status is still saying “Tracking Not Installed”. Is there anything you can think of that would be the cause of this? Thanks!

      Eric Flamm

      Depending on your situation, you may need to update the permissions on your header.php file to allow WordPress to save the update. My server defaults to read-only permission for most files (except for the “owner”, which is my hosting admin account, not WordPress). You need to enable “write” permission for World in order to allow WP to save the changes.

      Or not – there may be other reasons you can’t save the changes.

    lolly_spindler

    Hey Raelene,
    Is this only for self-hosted WordPress sites? My site is hosted with WordPress and I don’t have the editor option under appearance nor the option to install plugins and need to use analytics. Any suggestions?

      Raelene Wilson
      • Post author
      • 8
      • #11547

      Hi lolly_spindler. Yes, this post only applies to self-hosted WordPress sites. For questions about WordPress.com it’s best for you to contact their support team.

    khurram_shahzad5

    Hi Raelene, I cannot the find the body tag in editor. What should I do?

      DavidM
      • Staff
      • 7,766
      • #12

      Hi @khurram_shahzad5, I’m not Realene but will do my best to help!

      It sounds like you’re theme might not include the body tags in the header file so you’ll likely need to ask the theme developers about that.

      Or you could use our Analytics+ plugin to take care of that for you. It’ll ensure the code’s added as needed! :)

    khurram_shahzad5

    I have inserted the code in the editor but nothing is shown in tracking info?

      DavidM
      • Staff
      • 7,766
      • #12

      Hi @khurram_shahzad5, are you able to see the code that you added on the rendered page when viewing the source code? If it’s there, then it should track for the code being used.

    sunny_coast_reviewer

    Hi there – thanks so much for posting the instructions how to insert google analytics into a wordpress site. I have a premium theme (The Expound Theme) and find that when I go to Appearance the options I get are

    Themes
    Customise
    Widgets
    Menus
    Header
    Background
    Custom Design
    Mobile

    I’ve looked in all those settings and can’t seem to see where to insert my code – are you able to help please?

    Thanks in advance :-)

    DavidM
    • Staff
    • 7,766
    • #12

    Hi there @sunny_coast_reviewer,

    WordPress has a menu page available by default at Appearance > Editor. If you’re not seeing that, it’s possible you’re using Multisite, in which case it would appear in the network area at Network Admin > Themes > Editor.

    It’s possible you might have another plugin that’s removed the menu page or hidden it as well. Or it could be the theme’s removed it!

    You can test that by deactivating all plugins and switching to Twenty Fourteen theme. You should then be able to see it and can reactivate things to see what’s removing it.

    How does that work for ya? :)

    siddhesh_scindia

    Hi there,

    I’ve inserted the code in the header.php file.
    Although there was no on that file, i simply put it in there at the end and google showed up as tracked installed.

    Would this cause any tracking accuracy issues?

    Thanks
    Rey

      DavidM
      • Staff
      • 7,766
      • #12

      Hi @Rey, if Google’s recognizing the code and tracking it, that should work just fine. :)

    siddhesh_scindia

    Comment made to receive follow ups to my previous comment. Please excuse me. Thanks.

    gary_little

    Worked for me. Thanks.

    anoop_bhandari

    I am using to add analytics to my new blog http://www.newyearandchristmaswishes.com but it is not working from last many hours where as I am using analytics on my various other blogs too and there the problem like this never occured

      DavidM
      • Staff
      • 7,766
      • #12

      Hey @anoop_bhandari, I see the code added to your page so it should be tracking. Are you checking the correct property for stats?