How to Add Google Analytics 4 (GA4) tracking code to WordPress Website

The tools and plugins recommend in the site are the ones we use, have tried or tested ourselves and recommend to our readers. Marketing With WP is supported by readers like yourself. If you take an action (such as a purchase) we might earn an affiliate revenue at no extra cost to you.

WordPress users have the option to add Google Analytics tracking 4 code on the WordPress website and access the Google Analytics platform on the standalone platform.

For site admins who use Google Site Kit plugin, there is limited insights and data displayed on the dashboard. Using the standalone platform of Google Analytics is a much better option to access deeper user insights.

To add the Google Analytics 4 tracking code, you can either –

  1. Modify the theme file to insert the tracking code or
  2. Use a plugin to insert the tracking code

Add Google Analytics 4 tracking code to WordPress

There are currently two versions of Google Analytics – Universal Analytics and GA 4. The Universal Analytics is the older tracker that focuses more on sessions and page views. The newer GA 4 is more focused more towards users and their journey.

In this guide, we will show you how to set up GA 4 in your Google Analytics account, and then Add the tracking code to your WordPress website.

Step 1: Signup with Google Analytics

To connect Google Analytics with your website, the first thing you need to have is a Google Analytics account. Creating one is easy – you need to have is a Google Account (which everybody has).

So, go to Google Analytics, and sign in with your Google account.

Google Analytics signup using gmail or gsuite account
A gmail or gsuite account is required to create an analytics account

After successful signup, you’ll reach a page just like the one below.

click “start measuring” to get started with Google Analytics

Click on the Start Measuring button to continue.


Step 2: Setup your Google Analytics Account

The next step is to set up your account. On the next page, it will ask you to enter your account name.

Google Analytics setup - enter account details
Start the setup process by entering your account name

On clicking on Next, it’ll ask you to enter more details i.e. property name, location, time zone, and currency. Enter your details accordingly. You can also change these settings later.

After done, click on Next.

Google Analytics Property Setup
continue the setup process by selecting the right timezone and currency

Then, fill in your business info like industry category and business size. Below that, tick the boxes according to your preferences for the Google Analytics features you want to use.

Google Analytics Business Setup
Select the relevant checkboxes for your business to customize the experience

Finally, click on Create at the end of the page.

Google Analytics setup for customized experience
Select the relevant check boxes depending on your website’s goal and click “Create”

After that, a dialog box will pop up to accept the terms and conditions. Just select your country and accept it to move to the next step.

Google Analytics Terms of Service
Please click “I Accept” on Google Analytics Terms of Service

It’ll take a few seconds to get it ready.


Step 3: Setup your data stream

As soon as your account is created, it asks you to choose a stream type. You can choose from the options – Web, iOS, and Android. From there, select the Web option as you’re using it for your website.

Google Analytics choosing a web platform for website install
Since this analytics is for your website, please select “Web” platform

Now, another screen pops up to enter your website URL and name your stream. Make sure you pick the right URL prefix too – ‘http://’ or ‘https://’. After that, click on the Create stream button.

Enter your Website URL and Stream Nam on Google Analytics
Enter URL, stream name, & Click ‘Create Stream’

After doing so, you’ll get your stream details like measurement ID, global site tag, etc. on your next page.

Once the stream is created, you can copy the Global site tag (gtag.js) from the “Web stream details” section.


Step 4: Find GA4 Tracking Code and Copy the Global site tag code from data stream

Once the stream is created, you can copy the Global site tag (gtag.js) from the “Web stream details” section.

Google Analytics makes it easy to copy the GA4 tracking code

Once you copy the tracking code, you need to paste the tracking code in the header section of your website.


Step 5: Install a WordPress Plugin to insert GA4 tracking code

The next step requires adding a tracking code to your WordPress website.

When you access your website source code, you might mess it up if you don’t know what you’re doing. Therefore, we recommend using a plugin to insert the GA4 tracking code.

Here we are using the plugin ‘Insert Headers and Footers’.

If you use SEOPress WordPress SEO Plugin, we have a tutorial on how to add the tracking code using SEOPress.

So, leave the current GA4 tab as it is and open a new tab.

There, log in to your WordPress dashboard in a new tab. Then, go to

Plugins >> Add New

After that, search and install the plugin – ‘Insert Headers and Footers’.

Install ‘Insert Headers and Footers’

Step 6: Paste the GA4 tracking code in the header section

Now, go to the WordPress dashboard again.

Then, go to Settings >> Insert Headers and Footers

Paste the Global site tag code from Step 4, from the data stream to the “Scripts in Header” section, and click “Save”.

Paste the GA4 tracking code in the header section
Go to Settings >> Insert Headers and Footers and paste the tracking code in the header section.

After that, scroll down all the way to the bottom and click on the Save button.

Click “Save” after pasting the code

Remember to clear your website’s cache after pasting the GA4 code.


Step 7: Verify if your GA4 tracking Code is working

Now the GA4 tracking code is placed in the header section of your website. The tracker should load each time your website loads a new page.

Note: Before you verify, please clear the website cache if you are using a caching plugin.

Next, open a new incognito window and browse a few pages of your website.

Then visit your Google Analytics account and check the Realtime statistic dashboard.

Google Analytics Realtime Statistics dashboard
Google Analytics 4 Realtime dashboard shows the current user and their activity

If your tracking codes were installed properly, then you will see the user activity in the Realtime dashboard.

Conclusion

That’s it. Congratulations! That’s all you’ll need to do to add Google Analytics 4 tracking code to your WordPress site.

If your website is relatively new, you should check out our article on most important things to install and set up on your WordPress website that helps new website owners get a jump start.

If you found our content helpful, then please help share our content. Also, follow us on Facebook for more updates.

Frequently Asked Questions

  1. Signup with Google Analytics
  2. Setup your Google Analytics 4 Account
  3. Setup your data stream
  4. Find GA4 Tracking Code and Copy the Global site tag code from data stream
  5. Install a WordPress Plugin to insert GA4 tracking code
  6. Paste the GA4 tracking code in the header section
  7. Verify if your GA4 tracking Code is working

Once the “Web” Stream is created in GA4, the tracking code can be found under “Web stream details” section.

Once you copy the tracking code, you need to paste the tracking code in the header section of your website. You can use Google Tag Manager or use a plugin to insert the GA4 code on the header.

Ankit S J B Rana

Ankit S J B Rana

Ankit S J B Rana is a marketing enthusiast originally from the Himalayas of Nepal and currently based out of Bangkok, Thailand.

He is currently the Marketing Director at Mbrella Films and Filma.io

Marketing With WP is Ankit's blog full of marketing insights to turn your website into a 24 hour marketing machine.

Articles: 163