Add Google Analytics 4 to WordPress

If you’re a Google Analytics user, you’ve probably been hearing about GA4 or seen some emails from Google warning you that it’s time to switch. In fact, they are going to scrap the old version of GA in July of 2023. Which might leave you wondering how do you add Google Analytics 4 to WordPress?

What’s the difference

At tiny blue orange, we like to let the experts rock their expertise. Which is why we have partners for SEO strategy + help. But it is important for us to at least understand the pieces that connect to your site. So here’s what we know:

  • Privacy is a priority for Google (+ users of the internet), which can be problematic for business owners trying to understand their audience. GA4 is privacy-centric AND works with or without cookies.
  • It allows tracking from multiple platforms like websites + apps.
  • Previous versions of Google Analytics tracked by session. GA4 is event based. Giving you a better understanding of what users are doing on your site instead of how they landed on it.

My preferred way to add Google Analytics 4 to WordPress

The first thing you’ll need is your GA4 code, which is different than the old code. And it will have a new ID.

Note: Looking for help? Click the Gear icon or Admin in your Google Analytics Dashboard. Then under Property, click “GA4 Setup Assistant” + follow the steps.

Once you’ve set up your GA4 account, you’re ready to add Google Analytics 4 to WordPress. Click on Data Streams to grab your site code. You may need to add your homepage URL first.

Click on the stream to open a pop-up. Under the heading “Tagging Instructions” you’ll want to expand the “Global site tag” header. From there you can copy the code + paste it into 1 of 2 places: your theme settings or your theme header.php file.

Many WordPress themes have a spot in their settings area to add scripts like this GA4 code. What you’re looking for is something like “Header Scripts” or “Google Analytics” in the theme settings for your active theme.

Once you locate that text area, paste in your site tag + save your changes. The hardest part about this option is finding the option within your theme…if it exists. And if it doesn’t, you’ll add it to your theme.

If you’re comfortable making changes to your theme PHP files, you can add in your tracking code without needing to do any searching. If not, use the alternative option below.

But make sure you are ok making changes here + that you are using a child theme. Otherwise you could break your theme or lose all of your changes when the next update is released.

Now that the warnings are out of the way, head to Appearance > Editor. Once there, locate your header.php file in the right sidebar + click on it. When that file loads in the editor, locate the closing head tag. Paste in your GA site tag just before this bit of code.

</head>

Save your changes + refresh your site to make sure the site loads properly.

An alternative option for adding your code

To add Google Analytics 4 to your WordPress website in 5 minutes or less, head to Plugins > Add New. In the search bar type Google Analytics + select this plugin by Jeff Starr. Click the Install button + let it do it’s thing. In a few seconds, the Install button will have changed to say Activate — go ahead + click that.

Now that the plugin is ready to go, head to Settings > Google Analytics. Click the Plugin Settings heading to show the GA Tracking ID field. In that text field, place your Measurement ID number, select “Global Site Tag” + save the changes. That’s it, you’re done!

From here, you can check your data in GA in the next 24 hours + start to work on knowing your Google Analytics numbers to make the most of this free tool.

on your keyboard hit enter to search or esc to close