This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

How to Add Google Analytics to WordPress Websites

Updated on December 8, 2021

9 Min Read
google analytics wordpress

Successful marketing campaigns are based on visitor data. If you have detailed (and actionable) data on the visitors that come to the landing and information pages of your website, you can customize the mechanics of the marketing campaigns to attract the type of visitors you think are a good fit for your product/services.

Tracking visitors is an essential aspect of running an online business. This is one reason why there are several popular tools that help you track visitors and generate detailed segment reports on various web traffic analysis parameters. In the list of these tools, Google Analytics for WordPress is an excellent choice for analyzing visitor trends and traffic sources.

In general, when you install Google Analytics on WordPress, you get detailed insights into who visited your website and the user behavior on your website (such as page views, time spent on pages, bounce rate, the origin of the traffic, etc.). And opt for the best WordPress hosting provider to use these insights for exemplary performance results

In this article, I will discuss why should you use Google Analytics and how you can set it up on your WordPress website.

Why Should You Set up Google Analytics?

In general, a tool that provides detailed information about website visitors is an essential addition to your website. Google Analytics tracks visitors and where they come from (such as search engines, ads, click-to-pay networks, email marketing, PDF, onsite/offsite links). In particular, Google Analytics lets you:

  • Know who visited your website and when
  • Know what visitors are doing on your website
  • Know where visitors come from on your website
  • Know how visitors interact with your website content

Additional information includes visitor geolocation, browsers they use, default language, screen resolution, JavaScript support, etc. This data is very useful and can help you in website customization (such as theme, menu placement) and future website improvements.

A common case when you see less and less browser support for Flash, as indicated by the Google Analytics reports. In light of this data, you should plan to phase out all Flash-based assets to cater to a wider range of the visitor.

How to Add Google Analytics to WordPress?

Google Analytics is very easy to install on a WordPress website. You don’t need to have a lot of technical knowledge for this integration. In this tutorial, I will explain how to set up Google Analytics on WordPress websites and for WooCommerce stores, check out our WooCommerce Google Analytics integration guide.

However, you need to follow the steps in this tutorial so as not to miss out a crucial step and end up wasting your time.

Step 1: Create a Google Analytics Account

While there are two ways of integrating Google Analytics with WordPress websites, the first step remains the same.

You need to create a Google Analytics account. For this, go to From there, two cases arise:

  1. You already have a Google account. In this case, just fill in your credentials. If you use Gmail as your email provider, you have a Google Account by default.
  2. You don’t have a Google account. In this case, you must create one by clicking “Create account”. It takes a few seconds to enter your name, email address, password and related information (date of birth, mobile number, location, etc.).

Next, click the “Next” button.
create your google account

In the next step, complete your account details.

google account security

You will be invited to accept Google’s Privacy and Terms. Do it (as you really have no other choice).

Click the “I Agree” button.

google privacy and terms

Now go back to the Google Analytics homepage and click “Sign In” (top right of the screen, next to the “Create Account” button). Your Gmail address is already selected. You just need to enter your password and click “Continue”. Now click the “Sign up” button at the top-right side of the page.

sign up google analytics

You are invited to enter the information about your website, such as account name, website name, website URL, industry category, reporting time zone. After that, click the “Get Tracking ID” button.

Note: Remember to select “Website” at the top of the page.

get tracking id

Google then invites you to accept Google Analytics Terms of Service, click the “I Accept” button.

google analytics terms of service

You will then be taken to the homepage of your Google Analytics account. Since this is your first visit, you will see the “Tracking Code” page that displays your “Tracking ID” (something like UA – XXXXXXXXX-X) and your tracking code.

google analytics tracking code

You will need the tracking code to add Google Analytics to WordPress website.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src=""></script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
 gtag('config', 'UA-XXXXXXXXX-X');

Note: You can access to tracking code at any time from the Admin tab → Tracking Information → Tracking Code.

Step 2: Insert Google Analytics Code to WordPress

To install Google Analytics tracking code on the WordPress website, you have three options. I will present all three in methods in the order of increasing complexity.

Method 1: Copy/Paste the Tracking Code to Your Website Code (in the “header.php” file)

The first method might appear to be a bit scary at first, but it’s actually not that complicated.

Go to the WordPress Dashboard → Appearance → Editor menu and click the “header.php” file on the right side menu to edit the code.

All you need to set up Google Analytics to WordPress website is to copy the “Tracking Code” from Google Analytics and paste it into the header code. But not just anywhere! The Google Analytics tracking code must be pasted just before the </head> tag.

add tracking code in header

Method 2: Install a Google Analytics WordPress Plugin That Inserts the Tracking Code

The second method is the fastest and easiest. If your theme does not allow you to use Method 1, this is a great alternative.

The process requires installing a WordPress Google Analytics plugin. Like everything else, there are several great plugins in the official WordPress plugin repository. The vast majority of these plugins is free and the problem is that many plugins are unnecessarily complex and full of features that do not really add any value for the users.

To help you out, I will now mention two of the best Google Analytics WordPress plugins that I think get the job done without any fuss.

1. Google Analytics Dashboard for WP

GA Google Analytics is a simple, well-coded and powerful plugin. To install it, go to Dashboard → Plugins → Add New. Type “ga google analytics” in the plugins search box. The plugin should be at the top of the list, at the top left.

install ga google analytics plugin

Click the “Install Now” button and then “Activate” the plugin. Once the plugin is activated, you must configure it. Go to Dashboard → Settings → Google Analytics → Plugin Settings, copy and paste the “Tracking ID” you find on the “Google Analytics Tracking Code” page (see previous screenshots to refresh your memory).

paste google analytics tracking id

You must check “Universal Analytics / analytics.js” and “Include tracking code in page head (via wp_head)” box, which sets up Google Analytics on the WordPress website. At the end of the page, click the “Save Changes” button.

2. MonsterInsights

Google Analytics for WordPress by MonsterInsights is another popular Google Analytics WordPress plugin. It is a freemium plugin and is widely used because of its easy-to-use interface. Once the plugin has been installed, activate it and navigate to its settings page to link it with your WordPress with Google Analytics account.

install monsterinsights plugin

Click “Authenticate with your Google account” button and log into your Google account. In case of multiple websites under one Analytics account, choose the website you wish to track with this plugin and save settings.

monsterinsights google authentication

The plugin will take a few minutes to fetch tracking data and will display the live tracking data right in the WordPress dashboard.

monsterinsights dashboard

Since I just set up a new account it has no tracking data to be shown yet. Settings for data tracking can also be configured using the plugin settings option.

monsterinsights tracking

These settings include the way you like Google to track your website traffic. Other options include settings for Google Ads and ecommerce related tracking options. Note that not all options are accessible in the free version. The pro version comes with options such as forms, AMP for WordPress, Facebook Instant Articles and performance settings.

Method 3: Using Google Tag Manager

Go to Plugins → Add New → search for “google tag manager” in the text field → and then Install and Activate the plugin.

install google tag manager plugin

In the next step, go to Google Tag Manager and click on the Create Account button if you have not already signed up.

create google tag manager account

Enter the required details including Account Name, Country, Container Name. After that, click the Create button.

create container in google tag manager

Now agree with the Google Tag Manager Terms of Service Agreement and click the Yes button.

google tag manager terms of service

When you complete the signup process, you will see the following Google Tag Manager snippets. Click the OK button to get your Google Tag Manager ID.

google tag manager snippets

Now go back to plugin’s settings, paste your Google Tag Manager ID, and click the Save Changes button.

google tag manager plugin settings

You have successfully installed Google Analytics via Google Tag Manager.
Method 4: Hosting WordPress Google Analytics Locally
Google Analytics can be hosted locally on your server for better performance as it reduces external HTTP requests. To integrate this functionality, I will use a lightweight WordPress Google Analytics plugin, Complete Analytics Optimization Suite developed by Daan van den Bergh.

To install the plugin, head over to WordPress dashboard, search for “caos”. Activate the plugin and navigate to its settings page.

install caos plugin

Enter WordPress Google Analytics Code and select the location to place the tracking script. Other options are also available under “Advanced Settings“.

caos plugin settings

Note: This is not recommended by Google. However, this can help you in avoiding warnings like “leverage browser caching.”

Step 3: Make Sure Google Analytics Works Well

The last step is to verify that Google Analytics is indeed connected with the WordPress website and is working as intended.  The easiest way to test is to go to Google Analytics → Real-Time → Overview. Next, visit a page of WordPress website (the homepage, for example). If Google Analytics is connected to your website, you should see a bar. If so, it means that your website data goes back well in Google Analytics.

test google analytics

Note: It may take a few minutes or hours before the data is reflected in Google Analytics.

Wrapping up!

That’s it! You have now successfully set up Google Analytics for WordPress websites. To refine the data analysis for your websites, you can go to the configuration options of Google Analytics and create different profiles (including an unfiltered profile) by playing with filters, creating objectives or even setting up events/tracking ecommerce.

These configurations will not only allow you to analyze your traffic but also help improve the conversion of your traffic. In case of any questions, do not hesitate to ask us for advice in the comment section.

How to add Google Analytics WordPress?

In order to add Google Analytics WordPress, set up a Google Analytics account and paste the tracking code inside the header file of your website. Similarly, you can also find and use the best WordPress plugin for Google Analytics.

How to add Google Analytics WordPress plugin?

Search for the desired plugin using the “Add Plugin” tab and install the plugin. Once the plugin is installed, activate it and navigate to its setting page in order to connect it with Google Analytics account.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Beautifully optimized hosting for WordPress and Magento”

Arda Burak [Agency Owner]

Mansoor Ahmed Khan

Passionate about technology, entrepreneurship, and marketing, Mansoor Ahmed Khan is in computing since he knows how to type on a keyboard. His daily life is rocked by his family, projects, and his screen. Probably in this order, he likes to be convinced at least. You can reach out to him at [email protected]


Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!


Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!