Google Analytics shows how many people visit your website, where they come from and what they read. In 2011, I explained how to add the tracking code through the Thesis theme’s Site Options. Since then, Google has replaced Universal Analytics with Google Analytics 4. As a result, the old tracking codes no longer collect data. This guide shows how to add Google Analytics to WordPress the current way.
Step 1: Create a GA4 Property
Sign in at analytics.google.com with your Google account. Then go to Admin and create a property for your website. Next, add a Web data stream with your site’s address. Google will give you a Measurement ID that starts with “G-“, so keep it handy.
Step 2: Choose How to Add Google Analytics to WordPress
There are two reliable methods. For most site owners, the official plugin is the simplest choice. Developers, however, may prefer a lightweight snippet.
Option A: Site Kit by Google
Go to Plugins > Add New Plugin and search for “Site Kit by Google”. Install and activate it, then follow the setup wizard. Site Kit connects your Google account and places the tag automatically. Additionally, it shows key Analytics and Search Console figures inside your dashboard.
Option B: Add the Tag Yourself
If you prefer fewer plugins, add the Google tag through a child theme. Paste this into its functions.php file, replacing G-XXXXXXX with your Measurement ID:
add_action( 'wp_head', function () { ?>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXX');
</script>
<?php } );
Always back up your theme files first. Moreover, never add the tag in two places, because that doubles your figures.
Step 3: Verify Tracking
Open your website in a new browser window. Then check the Realtime report in Google Analytics. Within a minute, you should see your own visit appear.
Respect Privacy and Consent
Analytics collects data about real people. Therefore, mention it clearly in your privacy policy. If you have visitors from the UK or EU, use a consent banner that supports Google Consent Mode. Similarly, review India’s data protection rules if you serve Indian customers.
We Are Done!
Your website now reports visits, sources and engagement in GA4. Next, explore the Reports section and set up key events for enquiries or sales. If you would like help turning those numbers into decisions, see our AI business reports service or talk to our team in NOIDA.
Comments
Felt something? How about posting a comment below…