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.”
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).
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.
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.
Step 2: Find header.php, and Add Your Google Analytics Tracking Code Inside the <head></head>Tag
- 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
- 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
<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.
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.
Yes. In fact, generally speaking, if you want any of your scripts to be applied sitewide, this is the place.
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:
- Where Is the Head Tag in WordPress?
- Installing Google Tag Manager [GTM] on WordPress (Without a Plugin)
- How to Track Button Clicks With Google Tag Manager
- How to Set Up Scroll Depth Tracking in Google Tag Manager Post author
- How to Exclude Your Home Wi-Fi in Google Analytics Tracking, and Then Verifying the Exclusion
- All Other Topics and Posts
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.