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 Membership Site Plugin

If you're thinking about starting a paid, or just private, membership site then this is truly the plugin you've been looking for. Easy to use, massively configurable and ready to go out of the box!
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 Infinite SEO Plugin

Fully integrated with the SEOMoz API, complete with automatic links, sitemaps and SEO optimization of your WordPress setup - this is the only plugin you need to help you rank your site number 1 on Google - nothing else compares.
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.

Comments (39)

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

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

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

  3. 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/ on line 304

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

    Many thanks!

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

    • 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! ;)

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

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

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

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

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

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

    • 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! :)

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

    Custom Design

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

  9. 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? :)

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