How to Add Google Analytics To WordPress?

Updated on By

They say that if you don’t know where you are going, you’ll never get anywhere. For all of the effort you take to host, design, create content, and do everything to make your website successful, you could be missing out on critical data and information if you don’t use the power of analytics to make data-driven decisions.

For most website owners, marketers, and entrepreneurs, Google Analytics is a powerful and free tool that can help you quickly track the results of your marketing efforts. To install it, is the first step towards data-driven goodness that you should take.

After you install Google Analytics, You’ll be in a better position to make decisions by determining various data layers such as time on site, bounce rate, the geographic locations of your users, the devices they use to access your site, the content they engage with, and more.

To connect your WordPress website with Google Analytics is a fairly simple process. However, there are several options while there’s no right or wrong way to do it. You’d have to pick what works best for you.

Google Analytics for WordPress: Free or Paid?

While the core Google Analytics tool is completely free to use, Google’s Marketing Suite isn’t free. Google Marketing Suite comes with several advanced features for businesses that want to take advantage of the complete & powerful feature set available. For instance, some of the features include

  • Advanced funnel reporting and attribution modeling
  • Roll-up reporting More views, dimensions, and metrics per property
  • Unlimited and unsampled data

It can also be connected seamlessly with other Google products such as the Google Marketing Platform, Google Ads, YouTube, and several other Google tools if you ever wanted to do more with your marketing, tracking, and analytics efforts.

Paying for 360 also gives you access to dedicated support, including your own account manager. This alone can mak0e the subscription fee worth it. And about that subscription fee? It’s not cheap.

Analytics 360 begins at around $150,000 per year (invoiced monthly) and increases after your site receives more than one billion monthly hits. 360’s cost will price out many businesses. However, if you have the budget for both the service and an agency or in-house analyst to manage your analytics operations, consider investing.

Here are ways to add Google Analytics to WordPress:

Connect Google Analytics With WordPress: Your Options

If you were wondering how to add Google Analytics to WordPress, there are several ways to do it. There’s no right way or the wrong way, but include the code and using GA is a must. There’s the raw way (without a plugin) to add Google Analytics to your website (where you’ll actually add the tracking code for Google Analytics in the header section of your website so that all the pages can be tracked). Your Google Analytics code in the header php file is theme-specific. It’s bound to disappear if you change your WordPress theme.

Alternatively, you can add and install its code and use it by using Google Analytics plugins for WordPress.

Drop Google Analytics Code Into WordPress

For whatever reason, if you choose to add the code to your WordPress site without using a plugin (see below) or by using the Google Tag Manager, you should also understand a few pitfalls this decision might have for you and it can change the approach you take when it comes to how to add Google Analytics to WordPress.

Easy or hard – depends on you:

There are varying levels of WordPress users — from absolute newbies and non-tech savvy to WordPress developers. Now, adding Google Analytics to your site without a plugin is not as easy as with a plugin. Yet, while WordPress super users and developers can easily manage without a plugin (ever), most other users (Including marketers and business owners) will struggle when it comes to how to add Google Analytics to WordPress and hence are better off with a plugin or at least by using the Google Tag Manager to add GA.

You may lose tracking code:

WordPress has several thousand themes for you to choose from — from paid themes to free themes. When you switch your themes, you may forget to add the tracking code again to your new theme. In the period of time before you add your Analytics tracking code again, your visitors won’t be tracked. Or you might just forget to add Google analytics to your new theme (if and when you change it). If you used a plugin instead, your Google Analytics code will always be active thereby tracking your site even when you change themes or use custom designs.

Missing powerful Analytics features:

On top of adding the tracking code, some Google Analytics WordPress Plugins come with powerful features like events tracking, custom dimensions, file download tracking, eCommerce integration, and more. Without a plugin, it’s very time consuming to set up these features on your WordPress site or to add Google analytics with specific snippets of code for a particular functionality. Needless to mention, you’d also have to learn how to track each of these specific events by using code after you add the code.

Just in case, if you do want to add Google Analytics To WordPress without a plugin, here’s how you do it.

Before you do anything, make sure to backup your WordPress theme before you add Google Analytics (or any other code really). Just in case something goes wrong, you’ll always have the previous version of your WordPress website intact if you want to revert to it.

You’ll be directly editing the code that outputs your site, so a mistake as small as a misplaced comma could bring down your whole site. Be sure to make a backup just in case.

Step 1: Get Your Tracking Code

To get your code and as a first step to connect Google Analytics to WordPress, log into your Google Analytics account and select the website (if you have multiple websites or properties being tracked) for which you need the tracking code. Click on Admin in the left taskbar (on the top nav). In the property column, click Tracking Info, and then Tracking Code.


After clicking on the tracking info, you’ll see a dropdown. Find the Tracking code and click on it. You’ll then get the actual tracking code for the property you selected (above). The property’s tracking code usually starts with <!– Global site tag (gtag.js) – Google Analytics -> as shown below.

Copy the code so that you can paste this code as it is into your WordPress site. This connects your Google Analytics to WordPress.

Step 2: Add the Google Analytics Tracking Code to the header.php file

Now, are you wondering where to place Google Analytics code on your website? You should add the code to your header php file in the header section of your WordPress site.

Log in to your WordPress dashboard and navigate to Appearance » Theme Editor. Now click the Theme Header php(header.php) file on the right-hand side, under Theme Files (you may have to scroll up or down, depending on your theme).


Paste the tracking code you just copied from your Analytics profile before the closing </head> tag. This adds the code to your header php file.


Then click Update File.

That’s all you have to do to install Google analytics and to ensure that all the pages of your website are tracked by your tag, without a plugin.

For making sure that your advanced features work — such as enhanced eCommerce tracking, file downloads tracking, eCommerce transactions, and more. You’d have to work with your code (add other scripts), add goals, etc., to make it work.

Once you manage to get it working, you’ll manage to make Google Analytics and WordPress work seamlessly.

More from us:

Use The Google Tag Manager

Google’s Tag Manager is a handy tool to add analytics to WordPress. It also helps you keep all your JavaScript tags on it (so that you don’t have to keep them on your site). You can access the Google Tag Manager after connecting it to your Google Analytics account,

Note: In addition to Google Analytics, You can add and track several other tracking scripts such as the Facebook Pixel, The Quora Pixel, The LinkedIn Advertising Pixel, retargeting scripts, and several other pieces of code using the same Google Tag Manager. This helps you keep all your JavaScripts in one place and relieve your WordPress site of the excess code (if you choose to add all tracking codes to the header or footer files of your WordPress site).

Of course, the Google Analytics code is usually the first JavaScript tag that you are likely to add to your Google Tag Manager.

Here’s how to add Google Analytics to WordPress using The Google Tag Manager. Note that you’ll need to set up your account properly and also your Analytics account).

Go to Google Tag Manager and sign in. If you’ve already created an account for the property or website you want to track, it’ll show up as shown below. If not, create your Google Analytics account and/or Google Tag Manager account (can be set up in a few minutes, for each property or website you want to track).


Click through your account name in the Google Tag Manager dashboard and click on “Add a New Tag”.

Here’s the part where you’ll now assign the tag and the trigger — that which causes the tag to fire.

For the most basic Google Tag Manager setting for Google Analytics Universal Analytics tracking code, you can choose from one of the several pre-made tags already available inside The Google Tag Manager as shown below. For our purposes, let’s choose Google Analytics: Universal Analytics and proceed.

Click on your chosen tag (the Google Analytics: Universal Analytics tag, in our case) and choose page view for Track type.

Note: You can tag and track anything on your website (including page views, events, element clicks such as button clicks, and more).


Next, you’ll be asked to choose and configure a trigger. Choose Page view as your trigger and save your configuration.


That’s it. Your Google Analytics tracking code is now set up to make your Google Analytics and WordPress work together.

Deploy a Relevant WordPress Google Analytics Plugin

There are several dedicated WordPress plugins to make it easier for you to use Google Analytics and to add Google Analytics tracking code with WordPress (some more feature-rich than others). To add any of these plugins to your WordPress website, go to your WordPress backend, Plugins Add new and search for the plugin of your choice.

Here are a few main Analytics Plugins for WordPress:

Site Kit By Google

Site Kit by Google has been developed by Google’s own internal teams as a comprehensive, one-stop solution to deploy, manage, and get insights for your website. With Site Kit, you get an embedded search console to understand how Google displays your WordPress website in Google search and also track how many people see your website on Google along with other metrics that make sense to your business.

In the Google Analytics dashboard, You also get the complete analytics package, track Google Adsense, glean page speed insights (with tips on how to improve performance for page speed, specific to your site), integration with tag manager, and a way to optimize your site (no code needed) after adding Google Analytics.



WP-Matomo is another popular Google Analytics plugin for WordPress which is an “ethical” choice in your hunt for the right analytics tool for your business. Matomo is open-source software and is secure and yet transparent.

While it’s also a Analytics alternative, you can certainly import your data to help track everything that happens on your site to bring the power of Google Analytics to your WordPress site.

To be able to use Matomo, you’ll need the Matomo web analytics application. To do that, you’d either need the Matomo On-Premise application or the self-hosted Matomo.

Another notable feature of Matomo is that it also supports WordPress multisite networks. This enables you to track several WordPress installs within your network and bring rich data and analytics to your WordPress multisite set up.

WP Google Analytics Events


Think of WP Google Analytics Events as an additional plugin on top of the usual Analytics plugins you’ll use for your WordPress site. Now, instead of breaking a sweat trying to code Google Analytics code for specific events on your website (such as to track clicks on buttons, sign-ups for your lead magnets, or form sign-ups), you can use this plugin to track specific events on your website as it makes sense for your business.

The WP Google Analytics events can help you track links and form submissions, compare the performance of two different CTAs on any page, set up custom events, and allow you to track YouTube and Vimeo videos if you use the premium version of the plugin.


MonsterInsights is a fantastic WordPress plugin to help you squeeze the most of what Google Analytics has to offer. With features such as enhanced eCommerce tracking, form tracking, Event Tracking, and EU Compliance (GDPR), the plugin boasts of a comprehensive feature set that can help you make the best use of data pertaining to your website.

You can also benefit from page-level analytics, custom dimensions, and also link tracking on your website on top of everything else that the plugin does automatically for you.

The setup and integration with MonsterInsights can be done in minutes and you can then wait for a while for the data to come through.



The Analytify WordPress plugin for Google Analytics is a simple — yet powerful — WordPress plugin that can make you a data-driven entrepreneur, marketer, or blogger. It boasts of a super-easy installation (with one-click authentication). It offers a robust dashboard for analytics, real-time stats, enhanced eCommerce tracking, and more.

Analytify is also a premium partner making it a plugin that always operates with best practices, is updated regularly, and comes with support when you need it.

Google Analytics Plugin from ExactMetrics

As the name suggests this plugins helps you by fetching the Google Analytics reports right into your WordPress dashboard. It enables you to view custom reports from Analytics and draw data based decisions based on that for driving more leads.

It helps you do a lot more than just link Analytics with your WordPress website. There are event tracking features that lets you make productive changes to your website based on the user behavior.

There’s a free as well as paid version of this plugin available and you can choose one based on your requirements. Get accurate and real time reports about the performance of your eCommerce or business websites. You can even track the reports about your advertisement campaigns or affiliate program using this plugin.

This plugin also allows integration with different form plugins, WooCommerce for eCommerce performance tracking, and even some popular affiliate plugins. The plugin also supports translation so that you can localize your dashboard reports.

Looking for even more Google Analytics WordPress Plugin options? Here’s a comprehensive listing of Google Analytics Plugins for WordPress.

The advantages of using Google Analytics

Google Analytics is one of the best and most reliable tools to study the analytical data of your website. It gives you a behind the scenes view of the traffic and performance of your website.

If you own a website, and you are not using Analytics yet, you are missing out on some very important and actionable data about your website.

First of all, you should know how integrating Google Analytics into your WordPress website can actually help you. The following are some of the reasons why you should integrate Analytics into your website.

Its free & easy to use

The Google Analytics from Google itself is free and the interface is straightforward. There are clear titles and a little experiment with the options should help you get familiar with the options.

All you need for the access to Google Analytics is a Google Account. You can sign in and easily connect your website with Google Analytics and it will start showing you reports about the traffic on your website.

It helps you figure out where the users are coming from

The reports by Analytics will work on providing you with statistics from different areas of your website. Especially about the site traffic. There will be different reports to let you know the percentage of traffic using different devices.

It helps you know the keywords or pages that fetch you the maximum traffic, and the daily traffic data where you can see the graphical representation of how traffic status of a week or month, or a specified duration looks like. Moreover you can even compare different durations to see if a particular campaign has worked for you or not.

Understanding the type of traffic

The demographics data on your Google Analytics will show you exactly what kind of users are interested in your website. You may have started your website with a certain target audience in mind, but whom your content is actually attracting can be known through Google Analytics.

This lets you self-assess your goals by checking if the content of your website is reaching the relevant masses. If you find that the intended audience and that reported by demographics data is different, then you can take actions to fix it. You can either alter the type of content to make it more suitable for your audience or change your call to actions to make it more relevant to your audience.

Find out your strong and weak points

With the Analytics report you can easily find out the strengths and weaknesses of your website in terms of the most or least converting pages, your top performing pages, keywords, etc.

This helps you find the areas in your website that need improvements. You can even use the list of your best pages and keywords to optimize your content and design them for better conversions. On the other hand, you can even observe the pages to find out what works and what doesn’t for your website.

Helps you test the effectiveness of your SEO campaigns

Over time, you will need to reassess your website’s performance. This can be in terms of optimizing the overall performance, or to improve the conversions.

Google Analytics has easy options to let you compare two different periods. You can therefore compare the performance of your website before the campaign, and after the campaign. There are also features to let you compare the results of two different test pages.

Custom reports

With Google Analytics, it is not difficult to generate custom reports with just the fields that you need. There’s a simple process to create custom reports and with additional WordPress plugins, you can even display these custom reports right into your WordPress dashboard.

Therefore, you can keep a regular check on the important aspects of your website with the help of these custom reports.

Observe your positions on the search engine

Once you create your website and start updating it with content on regular basis, you would want to keep a track of its performance.

Google Analytics let you check the position of individual posts and pages on the internet.

Provides you data to take calculated decisions

Based on all the data that Google Analytics provides, you can make better decisions for the future. The reports will reflect the actual status of your site’s performance.

With that transparency, you can strategize and implement the modifications based on real data. From small decisions like content planning for the week/month, to big decisions to target more conversions, can be taken based on this data.

Keyword research and analysis

Keywords are very important when it comes to SEO. If you target relevant keywords, you can sure reach more people. You can capture the market with the right keywords and that is what Google Analytics helps you do.

Firstly, it lets you know the keywords that you are successfully targeting. Moreover, it will also provide insights on what keywords your visitors generally use to reach your page. You will also need Google Analytics to track the performance of your keywords.

Behavior and Conversions

With well integrated Google Analytics, you can easily track conversions as well as revenue. The free tool does not just let you track the effectiveness of your campaigns, but also provides you with exact reports about conversions of a certain page.

Therefore, it becomes easy to see what pages bring the most revenue and the pages that need more optimization as well as promotion in order to make them more profitable.

Real time data collection

With Google Analytics, it is possible to view the real time reports about the site’s traffic. You can just check how many people are currently visiting a page, their location, their type of device, etc.

Such a feature is actually helpful for real time performance monitoring. Google Analytics is frequently updated with new and improved features. Moreover, it can be easily connected to other services from Google like Google AdWords, etc.

As far as Analytics for WordPress is concerned, you can either choose to deploy the Google Analytics Universal Analytics code by yourself (as shown above) or use WordPress plugins for Google Analytics to make the job easier.

Either way, using Google Analytics for WordPress has never been easier and critical than ever before.

What’s your favorite way to use Google Analytics with WordPress? Please let us know in the comments below.

Further reading:

Share This Post:
Disclosure: This page contains external affiliate links that may result in us receiving a commission if you choose to purchase mentioned product. The opinions on this page are our own and we don't receive additional bonus for positive reviews.