How to Install Google Analytics on WordPress – [Complete Tutorial]

Google Analytics is an indispensable tool for tracking visitors to your website if you want to improve your digital marketing power.

However, there’s never just one correct way to do things. Installation methods differ across hosting platforms, of course. But even on just WordPress, there are several different ways to implement Google Analytics on your website.

In this guide, I’ll show you three ways to install Google Analytics to your WordPress site: using a WordPress plugin; inserting the code directly into your WordPress theme file; and implementing the code through Google Tag Manager.

With this overview, you can choose which is the best implementation approach for your tracking needs.

We have a lot to cover, so let’s dive in!

Requirements

In order to install Google Analytics onto your WordPress site, you’ll need to set up two prerequisites. First, you need access to your WordPress admin area. Second, you need to have your Google Analytics tracking ID.

Access the WordPress Admin Dashboard

To access your WordPress admin area, add /wp-admin to your domain name in the address bar of your browser. Use your WordPress account to log in.

WordPress admin dashboard with URL highlighted

You must have admin access to your website in order to install Google Analytics. If you are already logged in, you can also access the admin dashboard by hovering over your website name in the topbar and clicking on the Dashboard option.

Google Analytics Tracking ID

Your tracking ID will tell your website which Google Analytics account to send data to. Go to analytics.google.com and log in with your Google account. Once logged in, navigate to the account that you want to install. 

If you don’t have an account already configured for your website, you can create a new account in the Admin tab.

Google Analytics New Account configuration fields

For a WordPress website, you’ll click on the Website option. Then, enter an Account Name (which is typically your company name) and a Website Name. Finally, enter your Website URL. Make sure to remove the http:// at the beginning of your URL. You can manually choose if you’re on HTTP or SSL through the drop-down menu. 

Google Analytics New Account configurations with Account Name, Website Name, and Website URL fields filled in

Google Analytics will also ask you to select your industry and timezone. It is very important to ensure that the timezone you choose here matches up with the timezone on your website. By doing so, you’ll be able to accurately compare data later on. 

Google Analytics showing the industry category and the reporting time zone

You can also choose if you want to take part in the other data sharing options that Google Analytics provides. Whether and which ones to use is up to you.

Google Analytics account data sharing options

Once you’ve selected the boxes applicable to you, you can finish setting up your new account by clicking Get Tracking ID

Google Analytics New Account configuration settings with Get Tracking ID button highlighted

To proceed, you’ll need to agree to the data processing terms. These might differ depending on your location. Check the necessary boxes and click I Accept.

Google Analytics Terms of Service Agreement

Upon doing so, you should be able to get the tracking code that you need to install Google Analytics on your website. You can also find this tracking code in your Admin tab under the Property column by clicking Tracking Info and Tracking Code.

Google Analytics Admin Panel Tracking Info page with Tracking ID highlighted

3 Methods for Installing Google Analytics on WordPress

Now that we have WordPress admin access and our Google Analytics Tracking ID, we can install Google Analytics.

There are three main methods for installing Google Analytics on WordPress. You can install Google Analytics through a WordPress plugin; you can directly install the Google Analytics code into your WordPress theme files; or you can install Google Analytics through Google Tag Manager.

Using the MonsterInsights Plugin

To install Google Analytics using a plugin, start in your WordPress dashboard. Hover over the Plugins header in your menu and click the Add New option.

WordPress admin dashboard Plugins menu item and the Add New menu item highlighted

In the search bar, type Google Analytics to search for available plugins.

WordPress admin dashboard Add Plugins with Google Analytics in the search bar

Install and Activate the Plugin

There are lots of great plugins that can help you install Google Analytics. We like to use the plugin called Google Analytics Dashboard Plugin for WordPress by MonsterInsights. With over two million active installations, it’s one of the most popular Google Analytics plugins for WordPress. 

Add Plugins page showing Google Analytics plugin search results with Dashboard Plugin for WordPress by MonsterInsights highlighted

Click the Install Now button for this plugin. Once it is finished installing, the button will turn blue and say Activate—click this to implement the plugin on your website.

Add Plugins page with Install Now button highlighted

Connect Your Plugin to Google Analytics

Once you’ve activated the MonsterInsights Google Analytics plugin, you will be redirected to the MonsterInsights setup screen.

Here, choose the descriptor that best matches your website. Click Save and Continue.

MonsterInsights setup page

Next, just click Connect MonsterInsights to connect your WordPress website to your Google Analytics account.

MonsterInsights setup page with Connect MonsterInsights button highlighted

To authenticate your connection, select the Google account you are using in Google Analytics. Click Allow to authorize access between Google Analytics and WordPress.

Google account selection and connection authorization with Allow button highlighted

Here, we’ll select the website information from our Google Analytics account to tell MonsterInsights where to send its data. Choose the account view from your Google Analytics account, then paste in your tracking ID. Finally, click All Web Site Data.

MonsterInsights setup with account name, tracking ID, and All Website Data highlighted

Click Complete Connection to finish connecting your website to Google Analytics through MonsterInsights.

MonsterInsights set up with Complete Connection button highlighted

At this stage, you can choose from a few different tracking options. These options customize your tracking code to help you get the data you need.

MonsterInsights setup with  different tracking options highlighted

We’re just about done!

The final step is to click Finish Setup & Exit Wizard. Once done, you should have Google Analytics installed instantly. 

MonsterInsights setup with Finish Setup & Exit Wizard button highlighted

Testing

Now that you’re done with the installation, let’s verify that it’s actually working.

One way to test this is using a Google Chrome browser extension called the Google Tag Assistant. You can click on the plugin icon in your browser to open a window that conducts Tag analysis of your website on whatever page you’re on.

Google Chrome browser with extension Google Tag Assistant highlighted

Since we see a tag labeled Google Analytics, we know that it was installed on our website. However, if you click on the tag, the message No HTTP response detected appears. This is because Google Analytics is blocked on this plugin for people who are logged in as admins.

Although it seems inconvenient, it’s actually important so that Google Analytics doesn’t track your actions whenever you visit your website or test functions. There’s an easy way around this, so don’t worry.

Demo website with Google Tag Assistant showing No HTTP response detected

To get around this, simply open your website in a new browser window using Incognito mode. 

Demo website open in incognito browser window with URL highlighted

If you navigate around your website, you’ll be able to see your Google Analytics tag functioning correctly in the Tag Assistant extension. Since we haven’t logged into the website in the incognito window, we are experiencing the website as a user instead of as an admin.

Google Tag Assistant showing deployed Google Analytics with green colored tag

Another way to test our installation is to check your Google Analytics account and see if it is receiving data. On your tracking code page, click real-time traffic reports. (You can also see this by clicking Realtime → Overview in your home view.)

Google Analytics  showing the real-time traffic reports link

In your realtime report, you’ll see that Google Analytics just detected a pageview. So this means that a user on the website right now (that’s us!) is detectable to Google Analytics. 

If we continue to navigate on our website, Google Analytics should record pageviews that you’ll see in this report. This tells us that Google Analytics is correctly installed.

Google Analytics showing real-time traffic report with a generated page view

And that’s how to install Google Analytics on a WordPress site using a plugin!

I recommend this method for anyone who doesn’t have a lot of technical knowledge of web development and just needs an easy way to install Google Analytics.

The downside is that you have to install an additional plugin, which can potentially bog down your WordPress installation and slow down your page. This isn’t a problem if you’re only using a few plugins, but if you are running lots of plugins on your website, you might want to consider an alternative method.

Directly in the WordPress Theme Files

You can also install the Google Analytics code directly into your WordPress theme files. This is the most technical but also most customizable and powerful method.

Access Theme Editor

In the WordPress admin dashboard, let’s head over to the Theme Editor. Hover over Appearance in the side menu, then click Theme Editor

WordPress admin dashboard showing Appearance button and the Theme Editor button

If you haven’t been here before, WordPress will recommend that you use a child theme for any code that you want to add to your site. This is super important so that your additions don’t get overwritten the next time your theme updates. 

Thus, you’ll need to set up a child theme before you proceed. Click I understand.

WordPress admin dashboard Theme Editor with I understand button highlighted

Take the time to set up a child theme if you don’t already have one. This process may differ depending on what theme you’re using.

I have one already set up, so I’m going to continue by selecting the child theme and finding the Theme Header file. This is where we will be installing our Google Analytics code.

WordPress admin dashboard with Storefront Child Theme and Theme Header (header.php)

Add Global Site Tag Code Snippet to the Theme Header File

In Google Analytics, scroll down on your Tracking Code page. You should see the Global Site Tag, which is a piece of code that will install Google Analytics on your website. Copy the entire code snippet. 

Google Analytics Tracking Code page with Global Site Tag code and head instructions highlighted

So with our child theme file open, we can add our tag into the code. I suggest that you insert it right under the meta tags in the <head> section. 

WordPress admin dashboard theme editor with meta tag highlighted

Enter a new line after any meta tags, then simply paste the Global Site Tag in. 

The earlier in the code that the Google Analytics code fires, the more likely it is to send data even if the user navigates away or interacts with the page before the site has finished loading. 

WordPress admin dashboard theme editor with Global Site Tag pasted in the theme header

So now that you have this set up, click Update File to save your changes. 

WordPress admin dashboard with Update File button highlighted

Testing

To confirm that we have installed Google Analytics correctly, we will use a Google Chrome browser extension called the Google Tag Assistant.

With the Tag Assistant extension on your browser, navigate to your website and open the Tag Assistant. You should see two tags labeled Global site tag and Google Analytics, which means that they are sending data to your Google Analytics account.

Google Tag Assistant showing that the Global site tag with a green tag and the Google Analytics with a blue tag deployed

Another way to test our installation is to check your Google Analytics account and see if it is receiving data. On your tracking code page, click real-time traffic reports. (You can also see this by clicking Realtime → Overview in your home view.)

In your realtime report, you’ll see that Google Analytics has just detected a pageview. We generated this pageview by entering the site, so if you don’t already have a huge volume of traffic on your site, this is a good way to check your Google Analytics installation.

If we continue to navigate on our website, Google Analytics should continue to record pageviews, which you’ll see in this report. This tells us that Google Analytics is correctly installed.

Google Analytics showing real-time traffic report with a generated view

This is a relatively easy installation method for Google Analytics. If you are comfortable with copy-pasting code into an existing child theme, then this is a great path to take. You avoid slowing down your website with additional plugins, and it should be unaffected by any WordPress or theme updates.

The greatest challenge to this approach is creating a child theme if you don’t have one already. If you aren’t comfortable with doing this yourself and don’t have a developer to help you, I recommend sticking with the plugin installation.

Using Google Tag Manager

If you plan on using multiple tools for tracking and web analytics, you might want to install Google Analytics through another Google application: Google Tag Manager.

Google Tag Manager is a tag management tool. This means that it hosts all website tags (code snippets for tracking tools) in one centralized place. You can implement and manage these tags through the Google Tag Manager graphical user interface—in other words, without coding. 

Google Tag Manager containers for demo website

Create a GTM Account

If you don’t already have an account for your website on Google Tag Manager, head over to tagmanager.google.com, log in with your Google Account, and click Create Account.

Google Tag Manager All Accounts with Create Account button highlighted

The steps for this are similar to what we did with our Google Analytics account setup. For the Account Name, use your company name.

Google Tag Manager new account setup with Account Name field highlighted

Each container can only house one domain name, so for your Container name, it’s a good idea to use your domain.

Google Tag manager new account setup with Container name field highlighted

For the rest of the container setup, select Web as the container location and click Create.

Google Tag Manager new account setup with Web selected as the container and the Create button highlighted

Next, you’ll be directed to your new Google Tag Manager container. Here, you’ll be presented with the Google Tag Manager code snippet that we will use to install Google Tag Manager to your website.

Google Tag Manager container with Install Google Tag Manager popup highlighted

Add GTM Code Snippet to the Theme Header File

Just like the theme file installation for Google Analytics, you’ll need to install a container code snippet for Google Tag Manager into your WordPress theme files. Although this may sound like extra work at first, we won’t need to repeat this process to install Google Analytics or any other future tracking tools. This is why Google Tag Manager is a great installation tool if you’re planning on using multiple tracking tools.

The first step for installation is to copy the first code, which needs to be added to the <head> section. 

Google Tag Manager Install Google Tag Manager popup with head code highlighted

Next, go to your WordPress admin dashboard. Hover over Appearance in the menu and click on Theme Editor.

WordPress admin dashboard with Appearance menu item and Theme Editor highlighted

If you haven’t been here before, WordPress will recommend that you use a child theme for any code that you want to add to your site. This is super important so that your additions don’t get overwritten the next time your theme updates.

Take the time to set up a child theme if you don’t already have one. This process may differ depending on what theme you’re using.

Choose your child theme in the dropdown labeled Select theme to edit, then go into the Theme Header file. 

In the <head> section of your theme code, add a line and paste your Google Tag Manager code snippet. I recommend doing this right after any meta tags. 

WordPress admin dashboard Theme Editor with code from the Google Tag Manager pasted on the Theme Header

The earlier in the code that the Google Tag Manager code fires, the more likely it is to send data through its various tracking tools even if the user navigates away or interacts with the page before the site has finished loading.

Next, we need to add a noscript code snippet after the <body> tag in the theme code. In the Install Google Tag Manager popup, copy the second code snippet.

Google Tag Manager dashboard Install popup with body tag highlighted

You may have to scroll and search a bit to find the <body> tag in your theme code. Once you find it, add a new line and paste your Google Tag Manager noscript code snippet.

WordPress admin dashboard with noscript code pasted in the Theme Header after the body tag

Finally, click on Update File to save your changes.

Deploy Google Analytics Through GTM

So how are you going to deploy Google Analytics through Google Tag Manager? 

In Google Tag Manager, you have access to the website through the central snippet that we’ve just installed. We can install new tags and tools via the user interface without having to go back into the site code again.

Google Tag Manager interface workspace

Create a Google Analytics Tag

All you need to do to install and deploy Google Analytics (or any tracking tool) is create a Tag. You can do this clicking Add a new tag in the Google Tag Manager Workspace, or by clicking the Tags header in the side menu and clicking the New button.

Google Tag Manager Workspace with Add a new tag button highlighted

Give you Tag a name so that you can identify it later on. I like to use a naming convention that tells me what tool collects the data, what type of data is collected, and where the Tag is deployed. For this one, I’ll use Google Analytics – Pageview – All Pages.

Google Tag Manager new Tag configuration with Tag name highlighted

A clear and consistent naming convention will be especially important when you install Tags that track different events or send data to different tools. Since Google Tag Manager can’t record and send data retroactively, it’s important that you’re able to implement and edit Tags accurately so that you don’t miss any important data.

To make a Tag that will install Google Analytics, we’ll click on the Tag Configuration box and select the Google Analytics- Universal Analytics tag type.

Google Tag Manager new Tag configuration with Google Analytics - Universal Analytics selected as the tag type

For the Track Type, select Page View. Next, you’ll specify the Google Analytics account that this Tag will send data to. For the Google Analytics Settings, start by selecting the New Variable option.

Google Tag Manager new Tag configuration with Track Type set to Page View and Google Analytics Setting set to New Variable

Here, you’ll configure a variable that connects your Tag to your Google Analytics account. In the Tracking ID field, paste your Tracking ID from your Google Analytics account. 

Google Tag Manager variable configuration with Tracking ID field highlighted

I recommend also using this Tracking ID as the name of your variable. This is helpful if you are using multiple Google Analytics to track data on your website.

Google Tag Manager Variable Configuration showing Tracking ID field populated and Tracking ID set as variable name

All of the other variable configuration settings are already completed for you. Click Save when you’re done.

Google Tag Manager Variable Configuration with Save button highlighted

Add All Pages Trigger

Now we just need to define a trigger, which will tell our Tag when to fire. You can see that there’s already one available, which is the All Pages trigger. This will deploy the Tag on all pages across your website.

Google Tag Manager with All Pages trigger highlighted

When you’ve finished configuring your Tag and its trigger, click Save

Google Tag Manager Tag Configuration with Save button highlighted

Testing

Now that you have implemented a Tag, you can test it out by going into the Preview mode. Upon clicking on Preview, your browser will be redirected into a special mode where you can navigate your website as a user and test your Tag implementation.

Preview mode will show you when Tags are firing, but it won’t send Tag data to your tracking tools so that you don’t interfere with your analytics. Preview mode also only applies to your browser, so you don’t have to worry about other users triggering Tags that you’re not yet ready to deploy.

Demo website with browser in Preview mode, with GTM Preview & Debug Console across bottom of browser

In Preview mode, you’ll see the GTM Preview & Debug Console across the bottom of your screen. This will show you specific Tags that fire (or don’t fire) on your page.

Demo website in Preview mode with Tags Fired On This Page in Preview & Debug console highlighted

You can also cross-check that Google Analytics is properly installed in Google Tag Manager using the Chrome browser extension Google Tag Assistant. If you click on the extension icon, you can see that the Google Tag Assistant shows that Google Tag Manager and Google Analytics are deployed. 

Demo website in GTM Preview mode with Tag assistant showing Google Analytics with blue tag and Google Tag Manager with green tag deployed

You can also see in your real-time reporting that there’s one user right now. On your tracking code page, click real-time traffic reports. (You can also see this by clicking Realtime → Overview in your home view.)

In the example below, you can see that our page was sent and received by Google Analytics. We generated this pageview by entering the site, so if you don’t already have a huge volume of traffic on your site, this is a good way to check your Google Analytics installation.

If we continue to navigate on our website, Google Analytics should continue to record pageviews, which you’ll see in this report. This tells us that Google Analytics is correctly installed.

Google Analytics realtime traffic overview with generated page view

Publish Implementation to a Version

After testing, you know that your implementation is working correctly. However, the implementation you see in Preview mode is not active for other users whose activity you want to track.

In order to make your Google Analytics implementation live on your website, you’ll need to submit your updates to a Version. Click on the Submit button in the Workspace.

Google Tag Manager Workspace with Submit button highlighted

In the Submission Configuration window, you can give your Version a name and add a description. This helps you keep track of when each change is implemented on your site. You can even revert instantly to an older Version if you discover a problem or mistake with your current Version.

Google Tag Manager Submission Configuration with Version Name field highlighted

Finally, click Publish. Once done, your Version will be live on your website. 

Google Tag Manager Submission Configuration with Publish button highlighted

Now, you can go back to Google Tag Manager page and click Leave Preview Mode.

Google Tag Manager Workspace with Leave Preview Mode button highlighted

When you reload your page, you’ll be able to see in the Google Tag Assistant that Google Analytics and Google Tag Manager are properly installed.

Screenshot showing Google Analytics and Google Tag Manager deployed with blue tag

Now, don’t worry if those aren’t all green. If the tag icons are blue, it just means you’ve used a non-standard implementation (like installing Google Analytics through Google Tag Manager). But your data is still safely sent off to Google Analytics.

Installing Google Analytics through Google Tag Manager takes several steps, but it’s one of my preferred methods. The big advantage to this setup is that you will be more flexible once you want to do customization and really get into advanced tracking techniques.

Not only can you easily deploy Google Analytics, but also your Facebook Pixel, Google Ads tracking, and conversion tracking. You can even set up certain triggers for interactions such as button clicks, element visibility, or form submissions.

So, implementing your tools through Google Tag Manager is very versatile when it comes to expanding your tracking. Your tracking power will extend well beyond the scope of just deploying a tracking code like Google Analytics onto your page.

For me, setting up Google Analytics through Google Tag Manager is the best installation method since it gives you the advantage of expanding your tracking later on.

Summary

So there you have it. These are the ways on how you can install Google Analytics onto your WordPress website. You can accomplish this through a plugin, by installing code directly into  your theme file, or by deploying the code through Google Tag Manager. In any of these three cases, Google Analytics will track user activity on your site and help you boost your digital marketing.

I usually prefer to deploy this through Google Tag Manager even though it’s more challenging because it gives me more flexibility later on. But if you don’t want to work with the theme files on your website, the plugin method is the simplest and most beginner-friendly.

Want to learn more about how to maximize your online business potential using Google Analytics? Check out our FREE Google Analytics for Beginners Course! This course will run you through all the basics in five short lessons spread over five days.

Which implementation method did you pick? Or after reading this post, will you change your implementation method right now on your WordPress website? I’d love to know how you like to use Google Analytics on your website! Let me know in the comments down below.

JOIN US!

Master Data & Analytics with Measuremasters

Exclusive Courses & Workshops | Ongoing Troubleshooting | Support Resources, Tools & much more
guest
0 Comments
Inline Feedbacks
View all comments

Blog Categories

Join 30,000+ marketers getting exclusive resources and our latest content!

now it's time to

Start measuring like a master

Itching to jump into the world of MeasureMasters? This is what you have to look forward to.