How To Add Google Analytics To WordPress Without a Plugin

How To Add Google Analytics To WordPress Without a Plugin

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?

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:

  1. Add Google Analytics with a plugin;
  2. Create a Google Analytics WordPress plugin; or
  3. Add Google Analytics to WordPress without a plugin.

That last one? We’re show 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. 

Wait, What?

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

Create a Google Account So You Can Add GA Tracking Code Manually To Your Website
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

Sign in to Google Analytics
Sign in to Google Analytics
With your Google account created, you can now sign into Google Analytics. Select your email address and log in.
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.

The Admin area of the Google Analytics Dashboard
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.

WhereTo Find the Tracking Info for Google Analytics
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.

An Example of Google Analytics Tracking Code
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 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.

Go to Appearance > Editor
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.

Use your browser’s search function to look for the closing Head tag.
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:
Brenda Barron
Brenda Barron Brenda Barron is a freelance writer from Southern California. She specializes in WordPress, tech, business and founded WP Theme Roundups. When not writing all the things, she's spending time with her family.
Bonny Albo
Bonny Albo When she isn't working her magic as WPMU DEV's Blog Editrix, Bonny's probably drinking a cup of tea and deciding what part of the world she's exploring next.
Why do you want to add Analytics without a plugin? Were you able to add the Google Analytics tracking code to your WordPress site manually? Let us know in the comments.