How to Add Google Analytics to WordPress (Step by Step)
Originally published on CodingCush. Google Analytics tells you who visits your WordPress site, which pages they read, and where they came from, all for free. The catch is that WordPress does not include it: you have to
Originally published on CodingCush.
Google Analytics tells you who visits your WordPress site, which pages they read, and where they came from, all for free. The catch is that WordPress does not include it: you have to connect it yourself. This guide shows you the two reliable ways to do it, first with Google's own Site Kit plugin, then by adding the tracking code by hand, and finishes with how to check the numbers are actually flowing. No code experience is needed for the first method.
Before You Start: Get Your Measurement ID
Both methods need one thing from Google: a measurement ID. It looks like G-XXXXXXXXXX, a G followed by ten letters and numbers. To get one, sign in at analytics.google.com with your Google account, create a free GA4 property for your site, and open Admin, then Data Streams, then your Web stream. The ID sits at the top of that page. Google's own setup guide for Analytics walks through the same steps with pictures.
Keep that tab open. You will either paste the ID into Site Kit or into the tracking code, and copying it beats typing it: one wrong character and your data goes nowhere. If you already use Search Console, use the same Google account for Analytics, so both tools can talk to each other later. Our guide to Google Search Console for beginners explains what Search Console adds on top.
Method 1: Site Kit by Google (Easiest, Recommended)
Site Kit is Google's official WordPress plugin. It connects Analytics, Search Console, AdSense and PageSpeed to your site from one dashboard, and it adds the tracking code for you, so there is nothing to paste. This is the method to use unless you have a reason not to.
Step 1: install the plugin. In your WordPress dashboard go to Plugins, then Add New, and search for "Site Kit by Google". Click Install Now, then Activate. If you have never installed a plugin before, our guide to installing a WordPress plugin covers the same steps in detail.
Step 2: connect your Google account. Site Kit adds a Site Kit menu to the dashboard. Open it and click "Sign in with Google". Choose the Google account that owns your Analytics property, and approve the permissions it asks for. It needs read access to your Analytics and Search Console data; it cannot change your Google account settings.
Step 3: connect Analytics. Site Kit shows a setup checklist. Click "Connect Service" next to Analytics, pick the account and property you created, and confirm. If you already created a property, choose it from the list; if not, Site Kit can create one for you. When the checklist shows Analytics as Connected, you are done.
Step 4: check the dashboard. Give it a few minutes, then open the Site Kit dashboard. You should see your traffic, top pages and search queries without leaving WordPress. Real time data can take up to 30 minutes to appear, and full reports take up to 48 hours to fill in, so do not panic if the first screen looks empty.
The Site Kit by Google plugin page on wordpress.org: Google's official plugin that connects Analytics, Search Console, AdSense and Speed to WordPress.
Method 2: Add the Tracking Code by Hand
Use this method if you cannot use plugins, or if you want to know exactly what is on your pages. The tracking code is a small JavaScript snippet, called the Google tag. Copy it from your Analytics property under Admin, then Data Streams, then your Web stream, then "View tag instructions", and replace G-XXXXXXXXXX with your real measurement ID:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
That snippet has two parts. The first line loads Google's tracking library. The second block creates a dataLayer, defines the gtag function, and tells Google to start a session with your measurement ID. Paste the whole thing just before the closing tag on every page you want to track.
Where you paste it matters. The safe way is a header and footer plugin, which adds the code to every page without touching your theme. If your theme has a header.php file, you can paste it there, but only in a child theme: an update to the parent theme will wipe your edit. Never paste tracking code into a post or a page, because it will only run on that one page.
One warning: use only one method. If Site Kit is already adding the code and you paste it by hand as well, every visit gets counted twice and your numbers will be wrong. Pick Site Kit or the manual snippet, never both.
How to Check It Is Working
Open your site in a browser, then in Analytics go to Reports, then Realtime. Your visit should appear within a minute, under "Users in last 30 minutes". If nothing shows, wait five minutes and try again, and check the usual causes below.
For a deeper check, use Tag Assistant, Google's free Chrome extension. Open your site with it running and it lists every Google tag on the page, including your measurement ID, and flags any errors. It is the quickest way to prove the code is on the page and firing. Also confirm the property is the right one: the measurement ID in the tag must match the ID in Admin, or the data lands in a different property.
Give the reports time. Realtime shows visits within minutes, but the standard reports, pages, sources and devices, only fill in after a day or two. The first useful question to ask once data arrives is which pages get the most views, then where those readers came from: search, social or direct. Those two answers tell you what to write more of.
Common Mistakes and Troubleshooting
No data in Realtime. The usual cause is a wrong or missing measurement ID. Check that the ID in Site Kit or in your snippet matches the one in Analytics Admin exactly. Then check that the code is really on the page: view the page source in your browser and search for your G- ID.
Visits counted twice. You have two tracking methods running at once, usually Site Kit plus a manual snippet, or the same snippet in both a plugin and the theme. Remove one of them and the numbers will settle within a day.
Your own visits are missing. An ad blocker in your browser can block Google Analytics entirely, so test with the blocker off or in a private window. Some privacy extensions block the tag too, which is fine for testing but means your own stats will always undercount privacy conscious readers.
Data stops after a theme change. A new theme replaces header.php, so a manually pasted snippet disappears with the old theme. Site Kit survives theme changes because it is a plugin, which is one more reason to prefer it. After any theme change, recheck Realtime before you assume everything still works.
Frequently Asked Questions
Is Google Analytics free for WordPress?
Yes. GA4 is free, and Site Kit is a free plugin. You only need a Google account and a WordPress site you can install plugins on. There is a paid version, Analytics 360, but it is built for very large companies, not blogs.
Do I need a plugin to add Google Analytics to WordPress?
No, but it is the easiest way. Site Kit adds the code for you and shows the reports inside WordPress. The alternative is pasting the Google tag by hand before the closing head tag, ideally with a header plugin or in a child theme.
How long does Google Analytics take to show data?
Realtime data appears within a minute. Standard reports take 24 to 48 hours to fill in after the tag first fires. If Realtime shows your visits but the reports are empty, wait a day before worrying.
Does Google Analytics slow down my WordPress site?
Barely. The tag loads asynchronously, which means it does not block the page from rendering, and it is a small file served from Google's fast servers. If your site is slow, the cause is almost certainly something else, like images or hosting.
Will Site Kit work on WordPress.com free plans?
No. Plugins can only be installed on self hosted WordPress.org sites, or on WordPress.com Business and Commerce plans. On a free WordPress.com plan, use the built in Jetpack stats instead.
Conclusion
Adding Google Analytics to WordPress takes ten minutes with Site Kit and a little longer by hand. Install the plugin, connect your Google account, pick your property, and check the Realtime report to prove the data is flowing. Once the numbers arrive, the habit that matters is simple: check which pages people actually read, and write more of those.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.