WordPress GuideSEO → Add Google Analytics

How to Add Google Analytics to WordPress and Track Data

Have you ever wondered about your audience? Wanted to know where visitors to your website lived? How old they were? Google Analytics (sometimes referred to as just “GA”) can help you better gauge visitors and make informed, data-driven decisions regarding your website.

Keep reading to learn how to add Google Analytics to WordPress.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What is Google Analytics?

What can be tracked in Google Analytics?

You may be asking yourself, “If I connect Google Analytics to WordPress, what can be tracked?” Here are just a few of the things that can be tracked.

Geographical data

Google Analytics can allow you to see where your customers are. You can view by city, by country, by continent, and by subcontinent.

Source of traffic

If you’ve ever wondered, “How did my customers find me?” Google Analytics will help you. Here are a few types of traffic you can find in Google Analytics.

Technology

Are your customers viewing your site by using their cell phones or their desktop computers? Are they using Safari or are they using Chrome? Google Analytics answers these questions.

Event tracking

Once you’ve added Google Analytics to your WordPress site, you will be able to track events. Here’s a quick run-down of just a few types of web events that can be tracked:

Page views

How many pages did each visitor view? What was the average number of views across all visitors?

Session duration

Closely related to Page Views is Session Duration. How long was each visitor viewing your site?

Exit pages

What page was a viewer last viewing when they left your site?

Conversions

Google Analytics helps you track conversions. Conversions are when visitors to your site perform an action you value, such as subscribing to your mailing list or confirming a purchase. This is about converting random site visitors into loyal customers and clients, and turning clients and customers into dedicated fans.

Acquisitions

This is related to sources of traffic. Google Analytics helps you turn insights into results. In particular, by linking the Google Ads and Google Analytics accounts for your website, you can track which Google Ad Campaigns were most successful in bringing visitors to your site, your cost per acquisition, and how much each site conversion costs.

Behavior

Your website is your store window. Formerly known as “Content Experiments,” this feature of Google Analytics has been expanded and migrated to Google Optimize. You can leverage Google Analytics with Google Optimize to better understand split-tests for your WooCommerce site.

That’s a very, very brief introduction and broad overview of what Google Analytics can track. For guides, videos, and demos, head over to the official Google Analytics developer portal.

Why is Google Analytics important?

From reading the above list, you’ve probably already gleaned a few ideas you could use and are maybe now wondering how to add Google Analytics to WordPress. If not, here are a few more suggestions for why you should connect Google Analytics to your WordPress or WooCommerce site.

Integration

As suggested above, Google Analytics “just works” with most other Google platform services. If you have a Google Play app, you can use GA to track the Google Play Referral Flow from your associated WooCommerce site. If you have an active AdWords campaign with an email campaign component, you can align that data to track what’s working and what isn’t.

Attribution

Whether it’s a new sale or a new subscription, a new conversion is a delight. Whether you’ve had a managed WooCommerce site with us for years, or you’ve just decided to create your first online store, knowing why you gained a conversion is true bliss.

Imagine you’ve just got an unexpected rush of new conversions. Was it that new AdWords campaign? Did your latest Facebook campaign bring in those new clients? Or maybe it was the funny tweet from your college intern? Attribution (now in beta) from Google Analytics will help you stop wondering and start smiling as you better model the attribution for your conversions.

Recognition

Recognizing shifts in your website traffic and conversion rates spotlights new opportunities and helps you better focus your marketing efforts. For example, Google Analytics will help you break down which social media platforms are just bringing in new traffic and which platforms are now also bringing new conversions.

How to sign up with Google Analytics

Ready to see what your visitors are up to? Follow this quick-start guide and you’ll have your own Google Analytics 4 (GA4) property in minutes.

That’s it! You’re now the proud owner of a GA4 property and a fresh Measurement ID. Keep this ID handy because you’ll need it when we add the tracking code to WordPress in the next section.

How to install Google Analytics using headers and footers Plugin

After you’ve created a Google Analytics account and created at least one tracking code, you’ll want to know how to add Google Analytics to WordPress. To enable Google Analytics to start collecting data, you’ll simply add the tag from Google Analytics to the headers (or footers) of your WordPress site.

One easy way to add the newly created tracking code is to use the Insert Headers and Footers plugin.

Step 1: Install and activate the plugin. If you have one of our Managed WordPress or Managed WooCommerce plans.

Step 2: Insert code in your header or footer by going to the Settings > Insert Headers and Footers menu.

Step 3: That’s it! Google Analytics will now start collecting data.

Alternatively, add the code in functions.php

/**  * Add Google Analytics tracking code to the site header.  */ function add_googleanalytics() { ?>   <!-- Google tag (gtag.js) -->   <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>   <script>     window.dataLayer = window.dataLayer || [];     function gtag(){dataLayer.push(arguments);}     gtag('js', new Date());     gtag('config', 'G-XXXXXXXXXX');   </script> <?php } add_action( 'wp_head', 'add_googleanalytics' );

How to install Google Analytics using headers and footers Plugin

Adding Google Analytics to WordPress.com

How to install Google Analytics in WordPress

After a few days, Google Analytics will have enough data collected to begin offering you insights. Unfortunately, the official Google Analytics dashboard offers you so much data and ways of looking at the data that it collects, it can feel a little like drinking water from a firehose. Many first-timers to GA will find a Google Analytics WordPress plugin essential to not feeling overwhelmed.

Unfortunately, there isn’t an official WordPress plugin for Google Analytics. There is, however, an official plugin for WooCommerce called WooCommerce Google Analytics. Fortunately, there are quite a few 3rd-party plugins available. One such plugin is the MonsterInsights plugin.

Whichever plugin you choose, the installation instructions will be similar to the MonsterInsights installation instructions. The plugin will have a settings section where you can link the plugin to your Google Analytics account. This will redirect you to your account with Google where you will be informed there is a 3rd party app (your new plugin) requesting permissions to access your account.

Click ‘Allow’ if you want the new plugin to help you with your Google Analytics data.

While MonsterInsights is popular, several other plugins can link Google Analytics to WordPress just as easily:

That’s it! Now you know how to put Google Analytics on a WordPress website.

Verifying and troubleshooting your Google Analytics installation

Getting the code in place is only half the job. Make sure it works so you can trust the numbers you see.

Fix the issue that Tag Assistant or Realtime highlights, refresh, and repeat the steps until your visit appears. Once you see your own page views, you know Analytics is ready to track real visitors.

Setting up e-commerce tracking

Running an online store? Turn Google Analytics into your revenue dashboard by adding e-commerce tracking. Here’s how to connect WooCommerce sales data with your GA4 property.

With e-commerce tracking live, you can see:

Use these insights to fine-tune product pages, streamline checkout, and boost sales without guessing.

Privacy considerations for Google Analytics

Using Google Analytics means you’re collecting visitor data, so you need to follow privacy laws such as the GDPR (Europe) and CCPA (California). Keep these points in mind:

Following these steps keeps your analytics useful while respecting your visitors’ privacy.

Making the most out of Google Analytics

Whether you’re trying to start a new fan-club or start a new online business, you’ll want to make the most out of Google Analytics.

Narrow Focus — It’s easy to get distracted by the many, many metrics offered by Google Analytics. Have a set of just 5-10 indicators that are key to accomplishing your goals. Focus on those.

Regular Review — You’ve invested your valuable time into identifying your key metrics and designing custom reports for them. Now, remember to read the reports. You’ll want to review them weekly. Review daily if you’ve recently updated your site or launched a new campaign.

Make Changes — You’ve identified your KPI, you read the reports based on them, now use themHave you seen almost no change in your metrics since your latest AdWords campaign launched? Try changing your campaign keywords. Google Analytics can be a roadmap to success. When you realize you’re driving down the wrong road, you should change roads.

Google Analytics is incredibly powerful, it’s free, and it’s super easy to install Google Analytics on your WordPress site. What are you waiting for?

Getting started adding Google Analytics to WordPress

While you focus on getting Google Analytics set up on your WordPress website, we’ll worry about everything else. That’s the beauty of managed WordPress hosting. Check out our hosting plans to get started today.

Additional resources

Comprehensive guide to securing WordPress with ModSecurity

This guide provides a comprehensive overview of how to use ModSecurity to enhance the security of your WordPress site.

Three Ways To Get Google Analytics Connected To Your WordPress Site →

Keep reading to discover the three ways to connect WordPress and Google Analytics.

Why security matters for WordPress enterprise hosting

Use the blog as your guide to attacks to watch out for, security best practices, and steps to improve the WordPress protection you already have.

Michael Pruitt

Michael Pruitt is a Support Systems Administrator for Nexcess. He brings over a decade of experience to his current role. When not working, Michael can be found officiating roller derby bouts.