How to connect google analytics to wordpress

Google offers some of the best analytics software on the web. You can use it to monitor pageviews (traffic to your site), complete with demographic and location information. You can also view your current traffic in realtime, or really dig into reports about user behavior. But how do you add Google Analytics to a WordPress page? Here are a few options.

First, you'll need to register for a free Google Analytics account, so make sure to do that if you haven't already. Now we'll get you set up!

Is your WordPress site run on WordPress.com? You don't need to bother with plugins or modifying themes: support for Google Analytics is built in. Head to Settings > Traffic and you'll find a place to paste your embed code, no plugins or hacks needed. Read more at Wordpress.com.

How to Add Google Analytics to a WordPress Site With a Plugin

The simplest way to add the Google Analytics tracking code to your WordPress site so you can start learning about the people who browse your website. There are various options for the job but GA Google Analytics is clean and open source. To install it head to the Plugins section of your WordPress backend, then click Add New.

How to connect google analytics to wordpress

Search for GA Google Analytics and activate it. Next, you’re going to need to find your Google Analytics UA code. Head to Google Analytics, open the panel for the site you’re trying to add, then click Admin.

How to connect google analytics to wordpress

Next click Property Settings.

How to connect google analytics to wordpress

You will find your Tracking Id right at the top of this panel. Make sure to include the entire ID, including the UA- at the beginning and -1 at the end.

How to connect google analytics to wordpress

Now head back to your WordPress site and head to Plugins, then the settings for your plugin. Here’s how that looks for GA Analytics:

How to connect google analytics to wordpress

In GA Google Analytics you’ll need to open the Plugin Settings section.

How to connect google analytics to wordpress

Next, paste your GA Tracking ID in the appropriate box.

How to connect google analytics to wordpress

Click Save and you’re done!

Adding Google Analytics to a WordPress Site By Editing Your Theme

Don’t want to install a plugin just for Google Analytics? You can add the code manually to your theme. This is only recommended for advanced WordPress users. There’s a clear downside here: any updates to your theme will break the Analytics embed, so if you do this you’ll need to either avoid updating the theme or be willing to re-edit it. Still, if you want to avoid a plugin, this is the go-to method.

To get started you’ll need to find your Google Analytics tracking code. Open Google Analytics for the site you want to add, then click Admin in the bottom-left corner.

How to connect google analytics to wordpress

Click Tracking info...

How to connect google analytics to wordpress

...then click Tracking Code.

How to connect google analytics to wordpress

Copy the code in the Global Site Tag box.

How to connect google analytics to wordpress

Now head to your WordPress site and click Appearance > Theme Editor.

How to connect google analytics to wordpress

You will be warned about editing your theme. Click I understand to continue.

How to connect google analytics to wordpress

Now you can paste in the Analytics code you copied above. Make sure you put it above the </header>.

How to connect google analytics to wordpress

Click Update File and you're done.

You've now added Google Analytics to your website, so you can start learning about the people who browse it.

Want to get more out of Google Analytics? Zapier offers Google Analytics integrations, which connects Analytics with 1,000+ apps.

When you think about the greatest pairings of all time, you probably think about duos like Batman and Robin, Mickey and Minnie, and peanut butter and jelly. Then again, there is the very modern duo of WordPress and Google Analytics.

While they might not make the layman’s list of greatest partners, I bet they’d be pretty high up there for WordPress design, development, and marketing professionals.

If you have a WordPress website, then you should have Google Analytics (GA), too — no questions asked. It’s not like the two can’t exist without one another (as in any healthy relationship), but I’d argue that the universe just doesn’t seem right when the two aren’t paired up. The question is: how do you make this love connection happen?

Continue reading, or jump ahead using these links:

Pairing Google Analytics’ Tracking Code and WordPress

You’re most likely aware of at least one of three options available to help you connect Google Analytics to your WordPress site:

That last one? We’re showing you in this post where to find your Google Analytics code and how to add Google Analytics to WordPress without a plugin.

Note: we don’t recommend adding Google’s tracking code without a plugin. 

Benefits of Adding Google Analytics to WordPress Using a Plugin

That’s right. We’ll show you how and where to add the code for analytics tracking, but we honestly believe either of the other two options will serve you and your website better.

Why?

  1. Adding Google Analytics to WordPress with a plugin is easier, faster, and hassle-free;
  2. If you code GA into WP yourself,  you’ll have to add the Google Analytics code again when you switch themes; and
  3. A Google Analytics plugin sets up all features automatically, saving you time.

Now, we get it. If you want hands-on control of how GA tracks your data, then you’ve got to add the Google Analytics tracking code manually. Or, if you’re learning the basics of how WordPress works, then this is an easy task to start with.

Whatever your reasons (and do let us know yours the comments! we’d love to know), let’s jump in.

How to Add Google Analytics to WordPress Without a Plugin

You’re just six simple steps away from adding the tracking code manually.

Let’s count them down.

Step #1: Create a Google Account

How to connect google analytics to wordpress
Create a Google Account

Create a Google account if you haven’t already, and set up a property — aka your website.

Step #2: Log in to Google Analytics

How to connect google analytics to wordpress
Sign in to Google Analytics

How to connect google analytics to wordpress
With your Google account created, you can now sign into Google Analytics. Select your email address and log in.

Step #3: Get Your Google Analytics Tracking ID

Once you have logged into Google Analytics, go to the Admin area at the bottom-left corner of your Google Analytics dashboard.

How to connect google analytics to wordpress
The Admin area of the Google Analytics Dashboard

You’ll see three columns of admin settings controls. In the middle column, click on Tracking Info and then select the Tracking Code option.

How to connect google analytics to wordpress
WhereTo Find the Tracking Info for Google Analytics

Step #4: Copy Your Tracking Code

The Tracking Code tab will open and show your property’s unique tracking ID, along with the full Google Analytics tracking code.

How to connect google analytics to wordpress
An Example of Google Analytics Tracking Code

Once you get your GA tracking code, you will need to copy it in full.

Step #5: Log in to WordPress and Add the Code

Note: You should always create a child theme for your WordPress site before editing theme files (as you will in this next step). Check out our post about How to Create a WordPress Child Theme if you need a recap.

So, where in the HTML of your webpage should you place your analytics tracking code?

Log in to the backend of your WordPress website.

Once logged in, go to the Appearance > Editor tab in the sidebar. On this screen, you’ll see all of your site’s files displayed to the right, and each file’s Google Analytics code snippet displayed in the middle of the page.

How to connect google analytics to wordpress
Go to Appearance > Editor

Unless you’re only planning to track visitor activity on certain pages of your website (unlikely), you’ll want to insert the code somewhere that will automatically apply the tracking site-wide.

Where can you do that?

Look for the header.php file along the right-hand side. Click on it to open; the code editor will appear in the middle of your screen.

Look for the closing tag within the code. A simple Ctrl + F will help you quickly locate it.

How to connect google analytics to wordpress
Use your browser’s search function to look for the closing head tag

Once you find it, insert your cursor just before the tag and paste in your Google Analytics tracking code. Then click on the Update File button below the code editor to save your changes.

Step #6: Test Your Connection To GA While Waiting

After adding Google Analytics to WordPress, it takes anywhere from 24 to 48 hours for new data to populate.

So while you won’t start seeing the data on any traffic to your site immediately, you can test the connection you’ve established.

Check by returning to the Tracking Code page in Google Analytics. To the right of your Tracking ID is a Status Update. To confirm everything’s working properly, click on Send Test Traffic. This will open your site in a small window.

If all is well, your account should update to show an active user count of 1. Yay!

If the active user count doesn’t appear immediately, be patient. Google says this can take up to a minute.

Need More Help With Your Google Analytics Tracking Code?

If you missed our comprehensive guide to Google Analytics, take some time to read through it once everything is set up and ready to go on your WordPress site. It’ll give you a great introduction into what Google Analytics is, what it does, and what you can learn from the insights found within it.

And if you want to get even more granular with your tracking, check out our Tracking File Downloads With Google Analytics and WordPress.

Are you looking for an easy way to deliver your Google Analytics data to your WordPress clients? Check out how you can create pdf reports of GA dashboard data.

Ready? Set? Get Tracking!

You’ve come a long way since the start of this article – from not knowing how or where to put your Google Analytics tracking code, to getting your first test user counted and seeing your Analytics in action.

Congrats!

Now, it’s time to put what you’ve learned to work and get that code on your WordPress site.

If you need any help (and you’re a WPMU DEV member), contact our Support experts 24/7 with questions. Or, if you’re still figuring out whether a membership is right for you, post in the comments below. We’re happy to help you measure the metrics of your WordPress site with Google Analytics, in whatever way we can.

To your success!

Tags: