Back to “Technical setup”
Technical setup3 min read

Installing Google Analytics 4

Property, data stream, tracking code, consent management: a clean GA4 setup to reliably measure traffic generated by AI engines.

Installing Google Analytics 4 properly takes four steps: create the property and data stream, add the tracking code, wire up consent management, then verify data is actually coming in before you rely on it to analyze traffic from generative AI. This installation builds on the foundation already laid with Google Search Console and Bing Webmaster Tools: it adds traffic measurement on top of crawl measurement.

Create a GA4 property and data stream

On analytics.google.com, create a property (if you're starting from scratch, GA4 is now the only version Google offers). Fill in the timezone and currency, which can't easily be changed later. Then add a data stream of type "Web" with your site's URL: this stream generates a measurement ID (formatted G-XXXXXXX) used to connect your site to this property.

Install the tracking code

Two main methods:

  1. Direct gtag.js tag: paste the code snippet Google provides into the <head> of every page on the site. Simple for a small static site, but rigid if you plan to add other tracking tools later.
  2. Google Tag Manager (GTM): recommended as soon as the site has more than a handful of pages, or if you expect to add other tools (ad pixels, other analytics). GTM installs once via two code snippets (one in the <head>, one right after the <body> opens), and GA4 is then configured as a tag inside GTM — no need to touch the site's code again for every change.

Most CMSs (WordPress, Shopify, Webflow) also offer native GA4 or GTM integration through a dedicated settings field, which avoids editing source code directly.

Handle consent before any data collection

If your audience includes European users, data collection through GA4 falls under GDPR and generally requires prior consent for non-essential cookies. In practice, that means connecting GA4 to a consent banner (CMP) that blocks analytics tags from firing until the user has given their approval. Google offers a native option, Consent Mode, which lets GA4 keep modeling some data even without consent, without storing identifying cookies. This technical point goes beyond the scope of this lesson, but it directly affects how reliable your data is: an installation that ignores consent risks skewed data or a compliance problem.

Verify the data is actually coming in

Once installed, don't assume "it works" without checking. Two tools let you confirm this immediately:

  • The "Realtime" report in GA4: open your site in a tab, browse a few pages, and check that your visit shows up within a few minutes.
  • The Google Tag Assistant browser extension or GTM's debug mode, which show exactly which tags fire, in what order, and with what data.

If nothing shows up after a few minutes, the most common causes are a mistyped measurement ID, an ad blocker preventing the script from loading, or a misconfigured consent banner blocking everything by default.

The key events to enable from the start

GA4 automatically collects several events (page views, scroll, outbound clicks, file downloads) with no extra setup, as long as "Enhanced measurement" is enabled in the data stream settings — on by default, but worth double-checking. Beyond these automatic events, define at least one conversion event specific to your business (form submission, sign-up, purchase) so you can later measure whether traffic from generative AI converts differently than classic organic traffic.

Once GA4 is installed and reliable, the next step is learning to configure the GA4 reports that actually matter, particularly to isolate referral traffic from generative AI and track how it evolves over time.