RafflePress Logo

RafflePress Blog

WordPress Tutorials, Tips, and Resources to Help Grow Your Business

How to add google analytics to WordPress

How to Add Google Analytics to WordPress: Beginner’s Guide

Do you want to set up Google Analytics in WordPress?

Learning how your visitors interact with your website helps you keep them engaged and convert them into leads and customers. The easiest way to understand your visitors is to analyze your website traffic, which you can do with Google Analytics for free.

This article will show you why Google Analytics is important and how to add Google Analytics to WordPress step-by-step.

What Is Google Analytics?

Google Analytics is a web-based analytics service that tracks and reports your website statistics in the Google Analytics dashboard. The service can measure many different website metrics, including:

  • Who visits your website
  • What people do on your site
  • When users visit your site
  • How people find your site
  • How users interact with your content

With that information, you can discover patterns and trends that you can use to improve marketing campaigns, your website traffic and keep your target audience on your site.

How Does Google Analytics Work?

Google Analytics collects data from your visitors by adding a tag, commonly known as a tracking code, to each page on your site. That tag runs in visitors’ web browsers, collecting and sending information to one of Google’s data collection servers.

After collecting data from your website, Google Analytics generates customizable reports that help you visualize the data, such as:

  • Number of users
  • Bounce rate
  • Average session duration
  • Page views
  • Goal completions
  • Sessions by channel

Inside the Google Analytics dashboard, you can save profiles for many websites and see default or custom metrics for each site.

As mentioned earlier, you need to add a tracking code to each page of your website for Google Analytics to work. You should place the tracking code just before the closing </head> tag in your website header.

For many people, this isn’t easy because most WordPress website owners aren’t developers and don’t know how to work with code. 

But don’t worry.

We’ll show you several methods for adding Google Analytics to your WordPress website in this post. First, you’ll need to sign up for a Google Analytics account.

How to Signup for Google Analytics

Google Analytics is free, and all you need is a Google or Gmail account to sign up. Signing up for Google Analytics is quite simple, so follow these instructions to create your account.

Step 1. First, go to the Google Analytics website and sign up for an account.

sign up for a google analytics account

The page will ask you to log in with your Google Account, so you can use that to sign in if you have one. If you don’t already have a Google or Gmail account, you can create one from that page.

Step 2. After signing up for your Google Analytics account, you’ll see a screen prompting you to get started. Click the ‘Start Measuring’ button to enter the account setup process.

click the start measuring button

On the next page, you can enter an account name. Since this is an internal name, you can choose any name you like, then click Next to continue.

Enter a new account name

Now you can enter a property name for your Google Analytics account. This is typically the name of your website.

You can also choose the time zone and currency on the same page, then click Next.

Enter a property name to set up google analytics

The next screen lets you tell Google about your business. You can choose your industry, business size, and how you intend to use Google Analytics.

This information will help Google tailor your experience to your business needs.

Choose a business industry

Now click the Create button. Doing so displays the Google Analytics Terms of Service Agreement, so read through the agreement and click I Accept to continue.

Step 3. Now it’s time to create a data stream to collect your data. Since you want to set up Google Analytics in WordPress, choose the Web platform type.

Choose the web platform for your google analytics data stream

Clicking the Web option opens a window to set up your stream. On this page, you can:

  • Enter your website URL
  • Create a stream name (your website name)
  • Enable enhanced measurement
  • Review the data you plan to measure
Enter your website URL and name

Click the Create Stream button to move on.

Now you will see a screen asking you to choose a method for adding the Google Analytics tracking ID to your website.

You can add the tracking code to your site by using one of these options:

  • Global site tag (gtag.js) – The best option for CMS sites like WordPress
  • Google Tag Manager – For when you have many analytics and marketing tags
  • Google Analytics – If you already have  Google Analytics for another property

Because WordPress is a content management system, we will set up Google Analytics in WordPress using the Global site tag option.

Get your Google Analytics tracking code

Leave the browser window open for now so you can switch back and copy the code when you need it. From there, you can follow one of the methods below to add Google Analytics to WordPress.

How to Add Google Analytics to WordPress

There are several methods you can use to install Google Analytics in WordPress. We’ll share 3 methods in order of difficulty.

The first method is the easiest way to set up Google Analytics, and you should only use the last method if you’re a confident and advanced WordPress user. So pick the method that works best for you.

Note: You need to use only one of these methods on your website to avoid double-tracking page views in your Google Analytics account.

Method 1. Use MonsterInsights Google Analytics Plugin

We’ll use MonsterInsights to install Google Analytics in WordPress for the first method.

monsterinsights google analytics plugin for WordPress

MonsterInsights is the most popular Google Analytics plugin for WordPress, with over 3 million websites using it, including PlayStation, Bloomberg, Zillow, and more. It’s the easiest way to add Google Analytics to WordPress for beginners and advanced users.

Check out our MonsterInsights review for more information.

MonsterInsights offers a paid premium plugin and a free version that anyone can use. For this guide, we’ll use the Pro version of MonsterInsights for advanced features like eCommerce tracking, ads tracking, author tracking, and more.

Let’s get started.

Step 1. Install the MonsterInsights Plugin

First, install and activate the MonsterInsights plugin on your WordPress website. For details on how to do that, you can follow this guide on how to install a WordPress plugin.

After installing the plugin, go to Insights » Settings from your WordPress dashboard and enter your MonsterInsights license key. You can find your license details by logging in to the MonsterInsights website.

enter your monsterinsights license key

Click the Verify button to move on.

Step 2. Lunch the MonsterInsights Setup Wizard

Next, click the Insights menu item again and click the Launch Setup Wizard button. This will help you connect to MonsterInsights quickly and easily.

Launch the MonsterInsights setup wizard

On the first screen, choose whether your website is a Business Website, Publisher, or Ecommerce Site. Then you can click Save and Continue.

Select your website category

Next, you can enter your MonsterInsights license key if you haven’t already. So click the Connect MonsterInsights button.

Enter your monsterinsights license key

The next screen asks you to choose a Google Account to sign into MonsterInsights. It’s best to select the account you used to set up Google Analytics.

Connect monsterinsights to your google account

After, MonsterInsights will ask for permission to access your Google Analytics account. So click the Allow button to continue.

The last step is to select the profile you want to track. You need to select your website here and click on the Complete Connection button to continue.

Select your Google Analytics property

MonsterInsights will now install Google Analytics on your WordPress website. After, you can choose the recommended settings for your site.

Choose recommended settings for monsterinsights

The default MonsterInsights settings should work for most websites. However, if you use an affiliate link plugin, you’ll need to add the path you use to cloak your links. Doing that will allow you to track affiliate links in Google Analytics.

From there, click the Save and Continue button.

Step 3. Install Optional Addons

Next, MonsterInsights will suggest several addons that come with your plan or that you can upgrade to access. If you don’t want to install any addons, simply click the Save and Continue button.

Install optional monsterinsights addons

After, the plugin asks you to install WPForms, the best WordPress contact form plugin. You can click the Continue and Install WPForms button or click the Skip this Step link to continue.

Install WPForms

That’s it! You have now set up Google Analytics on your WordPress site. Click the Finish Setup & Exit Wizard button to head back to your WordPress dashboard.

Finish setup wizard. You now know how to add google analytics to WordPress

Google Analytics will take some time to start showing your website statistics. But when your stats are ready, you can view your analytics reports right inside your WordPress dashboard with MonsterInsights.

Simply visit the Insights » Reports page to check out a quick overview of your analytics data. It also comes with several addons to view other data.

monsterinsights overview report

For instance, you can use the popular posts addon to show your top-performing content and automatically add inline popular posts links to boost engagement.

Alternatively, you can use the eCommerce addon to check your products stats and automatically add your top-performing products to the end of blog posts to boost sales.

Method 2. Use Insert Headers and Footers Plugin

The following method for adding Google Analytics to WordPress isn’t as good as MonsterInsights. That is because it doesn’t allow you to set up advanced tracking. This method also doesn’t let you view your Google Analytics data inside WordPress.

First, open the browser window that has your Google Analytics tracking code and copy it to your clipboard. This is from step 3 of creating your Google Analytics account.

copy  your Google Analytics tracking code

Next, go to your WordPress dashboard and install the Insert Headers and Footers plugin. This plugin allows you to quickly add code to your WordPress site without directly editing WordPress theme files.

After activating the plugin, go to the Settings » Insert Headers and Footers page.

past your google analytics tracking code into the insert headers and footers plugin.

Now, paste the Google Analytics tracking code from earlier into the ‘Scripts in Headers’ section. Remember to scroll down and click the Save button to store your settings.

That’s it! You have now installed Google Analytics on your WordPress site.

Method 3. Add Google Analytics to Your WordPress Theme

The final method is for advanced WordPress users familiar with editing code. This solution is often unreliable because the code you add will disappear if you change your WordPress theme.

While we rarely recommend this method, you should ensure you have a WordPress child theme active on your website. A child theme prevents your tracking code from disappearing if you update your parent theme.

So when you carry out this method, ensure any theme files that you edit are from your child theme.

There are 2 ways to add your Google Analytics tracking code to your WordPress theme. 

1. Add Google Analytics code in header.php file

Go to your theme editor or file editor and open the header.php file for this approach. From there, paste the Google Analytics tracking code from earlier, right after the <body> tag.

Remember to save the file and upload it back to your server.

2. Add Google Analytics code to your theme’s functions.php file

For this method, open your WordPress theme’s functions.php file and enter the following code:

<?php
add_action('wp_head', 'rp_add_googleanalytics');
function rp_add_googleanalytics() { ?>

// Paste your Google Analytics tracking code here

<?php } ?>

Now paste your tracking code after the line telling you to ‘paste your Google Analytics tracking code here.’

You can now save and re-upload the file back to your server.

How to View Reports on Google Analytics Website

Google Analytics can show you a wealth of data that it collects from your website. You can view all of that data by going to your Google Analytics dashboard.

viewing reports in the google analytics dashboard

You will see ready-made analytics reports in the left-hand panel in your analytics dashboard. Each section has different tabs that you can expand to see more options, including:

  • Real-time: a real-time overview of your website traffic.
  • Audience: reports that help you understand your website visitors.
  • Acquisition: data that explores where your visitors came from.
  • Behavior: information about what users do after arriving on your site.
  • Conversion: a report that shows how well you’re doing compared to your goals. 

With this information, you can make data-driven decisions on optimizing your website for more traffic, engagement, leads, and conversions.

There you have it.

We hope this article helped you learn how to add Google Analytics to WordPress. If you have an online store, you can follow this guide to add Google Analytics to WooCommerce.

If you liked this article, please subscribe to our YouTube Channel for RafflePress video tutorials. You can also find us on Twitter and Facebook.

Let's Connect

Join Our Newsletter

Subscribe to get Free WordPress Tips and Resources

We do not sell or share your information with anyone.

Add A Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Copyright © 2022 SeedProd LLC. RafflePress™ is a trademark of SeedProd LLC

WPBeginner Verified Badge