The GA4 tracking code is a short JavaScript snippet keyed to a measurement ID that starts with G-. Installing it is a ten-minute job. Installing it without accidentally installing it twice is where most sites go wrong, and the cost is months of doubled metrics that nobody notices until a bounce rate near zero finally raises a flag.
This is the practical version: where the code lives, which installation method to pick, how to verify it, and what to check afterwards.
Where to find your GA4 tracking code
Go to Admin (the gear icon, bottom left), then under the Property column open Data streams. Click your web stream. The panel that opens shows your measurement ID at the top right — the G-XXXXXXXXXX string. That is your GA4 ID, sometimes called the GA4 tag ID or GA4 tracking ID depending on who is writing the documentation.
Scroll down in the same panel to “View tag instructions” (older interfaces call it “Tagging instructions”). You get two tabs: Install with a website builder or CMS, and Install manually. The manual tab contains the full gtag.js snippet, ready to copy.
A note on terminology, because it causes real confusion. Universal Analytics used a tracking ID formatted UA-XXXXXXX-1. GA4 uses a measurement ID formatted G-XXXXXXXXXX. There is also a Google Tag ID formatted GT-XXXXXXX used when a single Google tag serves multiple destinations. If a plugin asks for a “GA4 tracking ID”, it wants the G- string. And “GA4 pixel” is not Google’s term at all — people borrow it from Meta — but it means the same snippet.
Method one: the gtag.js snippet
The manual snippet looks like this, with your own ID substituted:
<!-- 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>
Place it immediately after the opening <head> tag, on every page. The async attribute means it does not block rendering, so the Core Web Vitals cost is small — but it is not zero, and stacking four analytics vendors this way is a real performance problem worth auditing separately.
Direct installation suits static sites, small custom builds, and anyone who is not going to add more tags later. It is the fewest moving parts and the fewest ways to break.
Method two: Google Tag Manager
If you expect to add conversion tags, third-party pixels, or custom events, install through Google Tag Manager instead. Create a Google Tag in GTM, set the Tag ID to your G- measurement ID, and trigger it on All Pages. Publish the container.
The benefit is that every subsequent tracking change happens in GTM rather than in your codebase, which matters when deployments require a sprint. The cost is one more system, one more publish step, and one more place where somebody can misconfigure a trigger.
The rule that prevents the most common disaster: choose one method per measurement ID. If GTM fires the Google tag, do not also hard-code gtag.js in your theme. Every page load will then send two page_view events, which doubles views, satisfies the engaged-session criteria automatically, collapses bounce rate toward zero, and inflates every key event that fires on a page load.
Method three: CMS and platform integrations
Most platforms accept a measurement ID directly and handle the rest:
- WordPress — via a plugin field, or a theme’s header settings. Check both; plenty of sites have the ID entered in two places.
- Shopify — through the Google & YouTube sales channel, which also wires up ecommerce events. Do not add the snippet to theme.liquid as well.
- Wix, Squarespace, Webflow — a dedicated analytics field in site settings.
These integrations are perfectly good. The failure mode is always the same: an integration configured months ago by someone who left, plus a manual snippet added by whoever inherited the site. Before you paste anything, view source on a live page and search for your G- ID.
Verifying the installation
Three checks, in order, take about five minutes.
- DebugView. In GA4, open Admin → DebugView. Load a page on your site with the Google Analytics Debugger extension or GTM preview mode active. You should see
page_viewappear once per load. Twice means duplication. - Realtime. Reports → Realtime should show your own visit within seconds. It will not show yesterday’s data properly, because standard reports take 24 to 48 hours to fully process.
- Tag Assistant. Google’s Tag Assistant lists every Google tag on the page and flags multiple instances of the same ID explicitly.
If DebugView shows nothing at all, the usual suspects are an ad blocker in your own browser, a consent banner blocking analytics scripts before acceptance, or the tag firing on a trigger that excludes the page you are testing.
The settings to fix immediately after install
A fresh GA4 property has defaults that will cost you later. Change these on day one:
- Data retention. Admin → Data settings → Data retention. The default for event-level data is 2 months. Set it to 14 months, which is the maximum on the free tier. Explorations cannot query beyond retention, so this quietly breaks year-on-year analysis if left alone.
- Internal traffic filter. Define it in the data stream settings, then activate it in Admin → Data settings → Data filters. A filter left in Testing state does nothing. This step is skipped constantly.
- Excluded query parameters. In the data stream’s tagging settings, list campaign or session parameters you do not want fragmenting your page paths.
- BigQuery export. Free, and the only way to own raw event data long term. Switch it on even if you have no immediate plans to query it.
- Enhanced measurement audit. Read the toggles. GA4 already collects scrolls, outbound clicks, site search, video engagement, file downloads and form interactions. Do not add manual tags for any of them.
- Search Console link. Admin → Product links. Without it, GA4 has no query data at all.
What the tracking code will never tell you
Installed correctly, GA4 gives you a clean picture of on-site behaviour. It gives you nothing about the search results that produced the visit — no query, no impressions, no average position, no sense of what you nearly ranked for. Organic Search in GA4 is a channel bucket. Search Console is where search performance lives, and the two will never reconcile exactly: expect a 5-15% gap between Search Console clicks and GA4 organic sessions, caused by bot filtering, consent refusals, redirects and the different counting points.
SEO Rocket connects Google Search Console and GA4 and treats them as ground truth for your own site’s performance, showing real clicks and sessions beside third-party index estimates with every source clearly labelled. Third-party volume and position numbers are modelled estimates; your own Google data is not. To be clear about the boundary: SEO Rocket does not replace GA4, build custom GA4 reports, or install tracking code on your site. Deploying the tag is still your job, and this guide is how you do it once, correctly.
A five-minute audit for a site you inherited
View source on three different templates and count occurrences of your G- ID. Open DebugView and confirm one page_view per load. Check whether an internal traffic filter exists and whether it is Active rather than Testing. Look at data retention. Then compare last month’s organic sessions in GA4 against Search Console clicks — if the gap is far outside 5-15%, something in the installation deserves another look before anyone reports on it.