How to Add Google Analytics to WordPress Website

How to Add Google Analytics to WordPress

Google Analytics is a powerful tracking and web analytics tool designed for website owners. When you add Google Analytics to your WordPress site, you can easily track powerful site traffic data such as the number of visitors to your site, your most popular posts, the amount of traffic your campaigns are bringing in, and so much more.

Unfortunately, many web owners don’t utilize this tool. The truth is, if you are not actively tracking your website visitors and behavior, you are leaving money on the table!

Google Analytics does more than just tracking – it gives your eyes and ears to your website. In this WordPress tutorial, you will see what Google Analytics can do for you, and also learn how to add it to your website.

Content:

What Google Analytics Can Do for You

Tells You What Kind of People Visit Your Website

With Google Analytics, you can check the countries where your visitors are coming from. But it goes beyond that. Google tracking also helps you determine your visitor’s language, the kind of browser they use, the size of their device screen, and lots more.

As a web owner, these analytics data are very useful, especially for marketing. If you are looking to target particular demographics of users, your website should fit their preferences.

For instance, if 80% of your visitors are mobile-only users and with browsers that support Javascript. Designing a highly responsive website is an absolute necessity.

Shows You What Visitors Do on Your Site

Google Analytics helps you understand the behavior of people on your WordPress site. You will be able to see the most visited pages, how users navigate from page to page, pages where users exit the site, etc. Even more, it checks the average amount of time users spend on every individual page.

With this data, you can reduce your website’s bounce rate, hence improving SEO.

Reveals How Visitors Locate Your Website

From the marketing point of view, it’s important to know how visitors locate your website. There are many ways visitors reach a website: social media, search engines, referral links, or direct visits. This data is available in Google Analytics.

Google Analytics report is very detailed. If most of your visitors come from social media, it tells you which exactly: Facebook, Twitter, LinkedIn, etc. Using this data, you can easily decide which campaigns to increase and which to discard.

Tells You the Time When Visitors Are Most Active

From your Google Analytics report, you can determine what hour of the day traffic to your website increases. With that data, you will know exactly when to publish content so as to get maximum views.

Ecommerce Tracking

If you run an eCommerce store, Google Analytics can be a plus. It helps you monitor your conversations and know how much you are earning.

That said, let’s see how to set up Google Analytics on a Website.

How to Setup Google Analytics on WordPress

Signing up for a GA account is the very first step before you can add google analytics to WordPress. To do this, head over to Google’s marketing page. Click on Sign in to Analytics.

sign in to analytics

You would see the following page

google analytics login

Put in your Google account details (which is your Gmail account), and click Next. You’ll be taken to the Analytics sign-up page.

Here, click on the Start measuring button to begin the registration.

google analytics registration page

Enter your account information on the next page and click Next.

enter your account information

After that, you need to create a new property to associate with your website. For this, enter the property name (you can use your business name) and then choose your time zone and default currency. You can click on Show advanced options to create a universal analytics property.

create a property for google analytics

On the advanced options, enter your website address and choose the option to create Google Analytics 4 (GA4) and Universal Analytics (UA) properties. Once done, click Next to continue.

google analytics 4 and universal analytics

Now, you need to enter more information about your business. Choose your industry and select the number of people on your team. You should also check all the boxes that apply to how you intend to use Google Analytics. Once done, click on Create to continue

how you intend to use google analytics

Finally, you need to accept the google analytics terms of use.

accept terms of use

You will be redirected to the google analytics dashboard afterward. To connect google analytics to your website, you need to copy your analytics code. For this, click on Configure tag settings.

configure tag settings for google analytics

After that, click on the Installation instructions button.

analytics code installation instructions

Next, navigate to the “Install Manually” tab. You will see the analytics tracking code you need to add to your website.

copy google analytics code

For now, simply copy the code, we will use it later on in this guide.

How to Connect Google Analytics to Your WordPress Website

Now you have your google analytics tags, it’s about time you added GA to your website. There are two ways to go about this: with a plugin, and without a plugin.

Setup Google Analytics With a Google Analytics Plugin

Plugins are there to make life on WordPress easy. There are quite a good number of Google Analytics WordPress plugins that can handle this task. One of the best – due to its intuitive interface – is Google Analytics by MonsterInsights. And that’s what we shall be using in this guide.

When using this plugin, you’ll not be needing the tracking analytics code you copied above. MonsterInsights connects automatically. Let us help you install Google Analytics in WordPress.

First, log into your WordPress Dashboard. Scroll down to plugins, mouse over, and click Add New. On the search box, enter “Monsterinsights”.

ga wordpress plugins

Install and activate the plugin. You will be redirected to the Setup wizard page. Alternatively, you can access this page by navigating to Insights >> Settings. Then scroll down and click on Launch Setup Wizard.

lauch monster insight setup wizard

On the “Setup Wizard” page, select your website’s category and click on Save and Continue.

monsterinsights plugin

Upon clicking Connect MonsterInsights, you would be asked to sign in to your Google account.

connect monsterinsights to your website

If you have multiple accounts, select the one you had initially used for creating the account. Next, click on the Allow button.

allow google analytics tracking id

On the next page, click on Complete Connection. You are almost done.

complete google analytics connection

For the next two pages, leave things at default settings. Skip things that aren’t necessary.

The last and final page is this. Click on Finish Setup & Exit Wizard to save your changes.

finish setup and exit

So here’s what the dashboard on Monsterinsight will look like.

wordpress dashboard analytics

If you noticed, the data here is flat. This is because it’s a fresh installation. It takes about 24 hours for Google Analytics to pick up meaningful statistics.

You can track your WordPress website stats here or do it directly from your Google Analytics account.

Setup Google Analytics Without a Plugin

Another technique for adding Google Analytics is by inserting the tracking code in the header.php file.

Sidenote: We will be editing theme files. So if you are not an advanced user, you can use the plugin method we explained above. Also, we recommend creating a child theme for this purpose. This way, you won’t lose custom codes when you update the parent theme.

To do this, login to your WordPress dashboard and then go to Appearance >> Theme Editor. On the right side, you will see your theme files. Locate the header.php file and click on it.

wordpress theme editor

Now scroll down and look for the closing head tag (</head>). You need to paste your GA tracking code just before the closing head tag. This is the code we asked you to copy earlier in this guide.

insert google analytics code to theme header

Once done, click on the Update File button to save your changes.

Alternatively, you can use the Insert header and footer plugin by WPCode to easily add this code to your website.

To be sure google analytics and WordPress are properly connected, open a page on your website. Then, log in to your Analytics account. Go to Real-time >> Overview. If you see 1 profile visit, your tracking code is working.

test google analytics real time data When you integrate Google Analytics with your WordPress website, it will show you real-time data on your website performance.

If you want to run marketing campaigns, the data provided can help you understand and identify where users access your website from.

Conclusion

The importance of accurately tracking your website’s visitors can’t be overemphasized. Not only does it help you make better marketing decisions, but it also helps you make better design decisions.

This guide has shown you how to add Google Analytics to your website. If you are a pretty advanced user, we encourage you to do this without a plugin. Either way, ensure you set this up and get it working.

If you want to grow your website, then you need to optimize it for search engines. You can check our guide on WordPress SEO to learn best practices for your website.

 This post was written by Sam Mulaim

Hello! I’m Sam - the founder and CEO of FixRunner WordPress support. When I started FixRunner one of my goals was to help people run a successful website and overcome WordPress issues. I don’t have much time these days to write new posts but when I do I enjoy it very much.

Last edited by: FixRunner Team