Categories
WordPress

How to Add Google Analytics to WordPress (Without a Plugin)

To add Google Analytics to WordPress, without a plugin, you’d need to access two different areas — based on how things are typically implemented. The first, is the tracking code inside Google Analytics. The second, is the header.php within WP.

Let’s tackle both one by one.

Step by Step Instructions for Accessing the Google Analytics Tracking Code

Step 1: Go to “Admin” Inside Google Analytics

From the left-most pane, all the way at the bottom, select the “gear” icon by the name of “Admin.”

navigating to the admin area in google analytics
As shown, hit the Admin Icon (the last option), to get started on grabbing the GA tracking code.

Step 2: Get to the Section Where You Have Your Tracking Code

Next, from the second column titled property, select the one you need to track from the drop-down, and then hit the tracking info line item. (Screenshot below for visual reference).

navigating to google analytics tracking info
As step 2, pick out the property you want to track and then head over to tracking info.

Note that as soon as you hit the tracking info option, Google Analytics will open up a new set of options right below. From those, you’d have to click on “tracking code.” See the image below for additional context.

final step to grabbing the google analytics tracking code
As mentioned, clicking on tracking info will reveal a new set of options. From those, select tracking code.

Now, if this is your first time adding the tracking code, you don’t have to worry about the sentence simply adding the config line.

Also, we’ll take a break here, as we’ve come as far as we could, as to what needed to be done inside GA. Later, we’d just have to copy-paste this code when we discuss WordPress setup.

Step by Step Instructions on Getting to the header.php in WordPress

Step 1: Head Over to the Theme Editor Area

From your WP dashboard, either via click or mouse hover on the “Appearance” option, select Theme Editor.

heading over to theme editor in WP
As your first step, head over to the theme editor.

Step 2: Find header.php, and Add Your Google Analytics Tracking Code Inside the <head></head>Tag

inserting google analytics tracking code in header.php
header.php is where you ultimately need to go, to add Google Analytics to WordPress.
  • As soon as you’re in the theme editor, from the right-most pane, locate your heder.php.
  • Consequently, WP will open up its code. In there, find the opening <head> tag.
  • Finally, right underneath, copy your entire Google Analytics tracking code, paste it, and save/update your header.php file to begin tracking your WP site with one of the most commonly used free tools out there.

FAQs Surrounding Google Analytics Tracking and WordPress

Do I Have to Insert As the First Item Inside the <head> Tag? What if It’s Not?

Google’s recommendation is just that! However, as long as it’s before the ending </head>, you should be fine. There are technical reasons why, one mostly about firing your GA script before any other, for accuracy.

What if I’ve Set Up GA Tracking With Google Tag Manager?

That’s completely fine! In fact, I have it like that as well. The only difference would be that instead of your GA tracking code, you’d copy-paste your Google Tag Manager code.
Hint: Scroll back up to the screenshot I shared. You’d notice I have the Google Tag Manager code.

Will Inserting the Google Analytics Tracking Code in header.php Work on All Pages?

Yes. In fact, generally speaking, if you want any of your scripts to be applied sitewide, this is the place.

How Do I Verify if I’ve Installed the Google Analytics Tracking Script Correctly?

I hear you. Adding the code is one thing. How do you know if it’s working the way it’s supposed to? There are tons of online resources to be found around this. Also, while I specifically do not have an exact post on this just yet, I have discussed verifying Google Tag Manager installation. So if that’s something you need to cross off your list, I am confident that’ll help.

You May Also Want to Check Out:

Conclusion

Honestly, adding Google Analytics to WordPress isn’t as big an undertaking as one may imagine.

The only caveat, and it’s something you should be doing anyway while working with WordPress code, is to ensure you have enough backups in place before making any tweaks to the core files. This way, in case you end up breaking something, you have a way to get up and running again.