In this article I describe how to install Google Analytics on your WordPress website using the Header and Footer plugin.
There are many ways to install GA: you can use specific plugins and many of the SEO tools (like RankMath) do this for you too. While those approaches do make it easy for you the advantage of using this method is that it makes it easier to apply addition tools that require you to add tags to the header, such as the Facebook Pixel. In my view, if you do it just this one way it will be easier to manage.
Currently there are two ways of doing this – using the old Universal Analytics tag or the newer GA4 tag. This article assume that you have already created a tag and provides instructions on adding it to your website.
The process is the same whether it’s a GA4 or a UA tag, however there is one extra step required for UA tags in order to ensure the data you collect protects private information of visitors to your site, which is important for compliance with GDPR.
How to Set up Google Analytics Property on your WordPress Website using the Header and Footer Plugin
Time 10 minutes
-
Create your Analytics Property
The steps for creating an Analytics property are not included here and it is assumed that you have already completed this step.
-
Find Your Global Site Tag JavaScript Code
Open Google Analytics.
If you have more than one account, select the Account you want to use and and the appropriate property.
Click the Admin wheel (at the bottom of the left menu sidebar) and the select Setup Assistant.
Click on Tag installation and select Web from the Data Streams list.
Now you’ll see information about the tag to use on your website, including the Stream URL (your website address), the Stream Name (this will match the Property settings) and the Measurement ID.
Scroll down to the Tagging Instructions section and select Global site tag (gtag.js) and copy the code. -
Copy the Tag Code into your Header and Footer Plugin
Copy the gtag.js code to your clipboard.
Go back to your WordPress website and select Tools and then Insert Headers and Footers.
Paste the gtag.js code into the Scripts in Header section.That’s it!
The final step is to go over to Google Analytics at the same time as visiting your site in another open tab or browser window.
If you don’t see anything and you’re running a cache tool (such as LiteSpeed) on your website, go back into the WP backend and clear it. Then go back to GA and check.
Go to the Real Time view and you should see a dot on or around your location . This means that it’s working.
If you have a very busy site and can’t tell from the Real Time view (that’s where you want to be of course so, fantastic!) you can check using the SiteChecker Pro website’s Google Analytics Checker.
Just type (or paste) your URL into the field and click the blue arrow button. The result will be shown below.
Choosing a Method for adding your Google Analytics Code
Although I wrote about the Code Snippets approach I think this is by far the easiest method. It’s also much simpler (and cleaner) than using a dedicated plugin because it’s so flexible: you could use this for adding Hotjar trackers, Facebook Pixel, Tag Manager – you name it. It’s fast and pretty simple and while it might seem daunting because you’re handling “code” you’re only copying and pasting so there’s really not much that can go wrong.
If you like found this post helpful and want to support me, please click the button below!
What if you need help?
If you don’t like the idea of messing with code or feel daunted by the idea of doing this yourself, you can book my time for the Google Analytics Quick Fix. In this time I can check the Google Analytics setup on your website, make any updates, or implement a completely new tag. Book it now!