How to Add Google Analytics to WordPress in 3 Easy Steps

Last Updated on February 4, 2020 by Sunny Staff

When you’re running a website, you need data to tell you what works and what doesn’t. Otherwise, you might as well throw spaghetti at a virtual wall and hope something sticks. And one of the most powerful analytics tools available is Google Analytics. 

Adding Google Analytics to your WordPress website can help you work more efficiently, fine-tune your site to exactly what your visitors want, and ultimately bring in more traffic and more customers. Read on to learn how to add Google Analytics to WordPress and why this is worth doing.

Why Use Google Analytics?

So now that you’re sold on WordPress, why should you worry about Google Analytics? Google Analytics is a powerful tool that can give you deep and meaningful insights about the visitors to your site. This helps you not only see what sort of success your website is having but also customize your content to optimize your results. 

With Google Analytics, you can see what people are viewing on your site, when they’re viewing it, and where they’re going from that page. This can let you know what’s working and what isn’t so you aren’t wasting time on content that isn’t resonating with your users. You can also see what sources are leading people to your site so you can pour your resources into the marketing efforts that work best.

Here are some of the mains areas of insight that Google Analytics can provide:

  • Geographical locations of visitors and leads
  • Browsing devices – even the operating systems your visitors are using
  • Most viewed pages
  • Browsing pathways
  • Bounce rates
  • The times of day that visitors come to your site
  • How they found your site (organic search engine results, social media, links from other websites, or directly)
  • What search queries were used to find your site
  • How they interact with your site (i.e. which links they click on, etc.)

Once you understand your visitors’ behaviors and preferences, you can modify your site and content to increase visitor engagement.

For example, you can add an extra language if you see a lot of visitors from a specific country. You can tailor your content to tie in with your top-performing posts. You can also tweak poor performing content to suit your target market’s interests better. 

Another area where Google Analytics can be of great help is in marketing. By analyzing where the majority of your traffic is coming from, you can focus resources on the top-performing sources (Is Linkedin more effective than Facebook? etc…). Google Analytics also allows you to track your marketing campaigns to see how effective they are.  

how to add google analytics to wordpress

1. Sign Up for Google Analytics

The first step to installing Google Analytics on your website is to sign up for Google Analytics. Once you have an account, you’ll use your plugin or custom patch to connect your account to your WordPress site. If you already have a Google account through Gmail, you’ll just need to sign into that account.

To sign up, head over to the Google Analytics home page. Once there, you will need to complete the following steps:

  1.     Click the ‘Sign up for free’ button (if you already have a Google Analytics account ignore this step and simply sign in)
  2.     Setup the password and email address for the account
  3.     Select ‘Website’ in the sign-up screen (not mobile)
  4.     Enter your details (account name, website, industry, and time zone)

After you’ve input all your account information, you should see a button that says “Get Tracking ID”. Agree to Google’s terms and conditions and get that ID; it should be a twelve-character passcode with two letters at the beginning. You’re going to need that to add Google Analytics to your site.

Once you have completed the sign-up process, you can now add Google Analytics to your website.

Note: If you already have a Google Analytics account, you can add additional websites to the account for tacking. It is not necessary to create a separate account for each. 

2. Install With or Without a Plugin 

There are two ways to install Google Analytics on WordPress: with or without a plugin. WordPress plugins are modular add-ons that allow you to customize your site. There are positives and negatives to both installing with and installing without a plugin.

Installing WordPress with a plugin is quick and easy, which can be important if you don’t have a lot of experience coding. But because Google doesn’t provide a direct plugin, you’ll have to work through another company’s version of a Google Analytics plugin or custom-code your own. Installing without a plugin can keep you from having to work through other companies but will require a little more expertise.

2a. Install without a Plugin

If you’re going to install Google Analytics without a plugin, one approach is to insert your tracking code into your header code for your website. Go to the header.php file in your theme that’s responsible for outputting the site header section. Then, right before the closing </head> bracket, insert your tracking code in <script> arrows and save the page. 

You can also add the tracking code to your functions.php file. You’re going to need to insert the following code into this file:

function ns_google_analytics() { ?>

  <script async src=”″></script>


window.dataLayer = window.dataLayer || [];

function gtag(){dataLayer.push(arguments);}

gtag(‘js’, new Date());

gtag(‘config’, ‘UA-123456789-1’);




add_action( ‘wp_head’, ‘ns_google_analytics’, 10 );


Be sure to replace the tracking ID in this code with your own tracking code. The tracking ID is your unique ID in this format: UA-XXXXXXXXX-X

2b. Install with a Plugin

If that all looks like far too much code for you, you can also install using a plugin. This skips the code bit and removes the risk that your code will get lost when you run updates on your site.

To install Google Analytics through the use of a plugin, you will need to do the following:

  1.     Go to Plugins > Add New in the backend of your site
  2.     Search for ‘Google Analytics’
  3.     Select the plugin of your choice (a popular option is MonsterInsights)
  4.     Click ‘Install Now’ and activate the plugin once it has finished installing
  5.     Navigate to the newly installed plugin and follow the provided steps to connect to Google Analytics. Go to the settings menu of your plugin and look for something that says “Authenticate with your Google account.”

As you can see, this method of installation is very simple. If you would like more information on the different Google Analytics plugins, check out this post

3. Adjust Your Tracking Settings

Once you have your Google Analytics account hooked up to your WordPress website, you need to adjust your tracking settings and start running reports. You may want to configure Analytics to ignore certain site traffic (such as the internal traffic from your business) or control who can run analytics reports. You can also switch on demographics tracking options to give you better insights into who’s visiting your site.

With all your settings in place, check in on your Analytics account regularly. You should be able to see fluctuations in traffic and use that data to figure out what’s working on your site and what isn’t.

Learn How to Add Google Analytics to WordPress

Knowing how to add Google Analytics to WordPress is one of your first steps to getting better insights into what’s working on your site (and not working). Whether or not you choose to use a plugin or not, setting up analytics doesn’t take long and is well worth the effort.

If you’d like to get help adding Google Analytics to your WordPress site, feel free to drop us a line. We’re where WordPress websites shine, and we’re here to help you make yours the best it can be. Contact us today to start living the sunny side of WordPress site management!