Method 1 gtag.js Direct code install Paste in <head> or Method 2 via GTM Recommended approach Full tag management GA4 Property G-XXXXXXXXXX Data stream · Reports Install Google Analytics 4 on Your Website GTAG.JS · GTM · POST-INSTALL CONFIGURATION

Key takeaways

  • There are two ways to install GA4 — directly via gtag.js code or through Google Tag Manager. GTM is recommended for almost all cases
  • You need a GA4 property and a web data stream before you can install anything — the Measurement ID (G-XXXXXXXX) comes from the data stream
  • After installation, set data retention to 14 months, filter internal traffic, and link to Google Search Console
  • Verify your installation using GA4 DebugView before considering it complete
  • Never install GA4 twice on the same page — duplicate tags cause inflated session and event counts

Installing GA4 is the first step — but the way you install it determines how much flexibility you have for everything that comes after. A direct gtag.js install is quick but rigid. A GTM-based install takes a few extra minutes but gives you a proper foundation for all your future tracking needs.

This guide covers both methods, platform-specific notes, and the post-installation steps that most guides skip but that actually determine whether your GA4 data is trustworthy.

Before you install — what you need

Before touching any code, make sure you have:

  • A Google account with access to Google Analytics
  • Access to your website's code or CMS
  • If using GTM — a GTM container already installed on your site, or the ability to add scripts to your site's <head>
One property per website

Create one GA4 property per website. Do not reuse a property across multiple domains — this corrupts your session data and makes attribution impossible to trust. If you have multiple related domains, use cross-domain tracking within a single property rather than creating separate properties.

Creating a GA4 property and data stream

1

Create a new GA4 property

Go to analytics.google.com → Admin → Create → Property. Enter your property name, select your reporting time zone and currency. These cannot be changed later without affecting historical data, so get them right now.

2

Create a web data stream

In your new property, go to Admin → Data Streams → Add stream → Web. Enter your website URL and stream name. GA4 will generate your Measurement ID — it starts with G- followed by alphanumeric characters. Copy this — you will need it for the installation.

3

Note your Measurement ID

The Measurement ID (G-XXXXXXXXXX) is the unique identifier for your data stream. It is what connects your website's tag to your GA4 property. Keep it handy for the next steps.

GA4 Account Structure GA4 Account GA4 Property Web Data Stream G-XXXXXXXXXX One account → one or more properties → one or more data streams per property
Fig 1. — GA4 account hierarchy. Your Measurement ID lives at the data stream level.

Method 1 — Direct gtag.js installation

This method involves pasting Google's tag snippet directly into your website's HTML. It is the fastest approach but gives you the least flexibility for future tracking changes.

Paste this snippet in the <head> of every page on your site, replacing G-XXXXXXXXXX with your actual Measurement ID:

HTML — GA4 gtag.js snippet
<!-- 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>
When not to use direct gtag.js

If you plan to add any custom event tracking, conversion tracking, or other tags in the future — do not use direct gtag.js. The moment you need to change anything, you will need developer access to edit code files. GTM gives you that control without touching code.

Method 2 — Installing via GTM (recommended)

This is the right approach for almost every professional implementation. GTM gives you a tag management layer that lets you add, edit, and remove tags without deploying code changes.

1

Make sure GTM is already installed on your site

If GTM is not on your site yet, install it first. GTM provides two snippets — one for the <head> and one for the <body>. Both are required. Once GTM is on your site, you manage all other tags through the GTM interface.

2

Create a new tag in GTM

In GTM, go to Tags → New. Click Tag Configuration and select Google Tag. Enter your Measurement ID (G-XXXXXXXXXX). This is the modern tag type that replaces the old "GA4 Configuration" tag.

3

Set the trigger to All Pages

Under Triggering, select the built-in All Pages trigger. This ensures GA4 loads on every page of your site. Name the tag clearly — "GA4 — Google Tag" or similar.

4

Preview and publish

Click Preview in GTM, visit your site, and confirm the tag fires. Then Submit → Publish your container. GA4 is now live.

GTM — Google Tag configuration summary
Tag type:       Google Tag
Tag ID:         G-XXXXXXXXXX  (your Measurement ID)
Trigger:        All Pages (built-in)
Tag name:       GA4 — Google Tag

// That's it. GA4 will start collecting data
// as soon as this container is published.

CMS-specific notes

Platform Recommended approach Where to add
WordPress Install GTM via a plugin (e.g. GTM4WP) then add GA4 tag in GTM Plugin settings → GTM container ID
Shopify Use Shopify's native GA4 integration via the Google channel app, or GTM via theme.liquid Online Store → Themes → Edit code → theme.liquid
Webflow Add GTM snippet via Project Settings → Custom Code, then manage GA4 in GTM Project Settings → Custom Code → Head code
Wix Use Wix's built-in GA4 integration or add via Marketing Integrations Settings → Marketing Integrations → Google Analytics
Custom HTML Add GTM snippet to your base template, manage GA4 in GTM Base HTML template → <head> section

Verifying your installation

Never assume your installation worked. Always verify before considering it complete:

1

Use GA4 DebugView

Install the Google Analytics Debugger Chrome extension. Visit your site with the extension enabled. In GA4, go to Admin → DebugView. You should see events appearing in real time as you browse. The page_view event should fire on every page load.

2

Check Realtime reports

In GA4 → Reports → Realtime, you should see yourself as an active user. If you see data here, GA4 is receiving events from your site.

3

Inspect network requests

Open Chrome DevTools → Network tab. Filter by "collect". You should see requests going to www.google-analytics.com/g/collect on each page load. If you see these requests, the tag is firing correctly.

Essential post-install configuration

Installation is just the beginning. These configuration steps should be done immediately after verifying your tag is live:

1. Set data retention to 14 months — GA4 defaults to 2 months. Go to Admin → Data Settings → Data Retention and change to 14 months. Do this now before you lose early data.

2. Filter internal traffic — Go to Admin → Data Streams → your stream → Configure tag settings → Define internal traffic. Add your office IP address. Then go to Admin → Data Filters → activate the Internal Traffic filter. This stops your own visits from inflating metrics.

3. Link Google Search Console — Go to Admin → Search Console Links. This brings organic search keyword data into your GA4 reports — essential for understanding SEO performance.

4. Link Google Ads — If you run Google Ads, link your Ads account via Admin → Google Ads Links. This enables conversion import and audience sharing between the two platforms.

5. Configure Enhanced Measurement — Review which Enhanced Measurement events are enabled (scroll tracking, outbound clicks, file downloads, video engagement). Disable any you plan to track via GTM to avoid duplicates.

6. Mark conversions — Go to Admin → Events and mark your most important events as conversions — form submissions, purchases, key engagement events. GA4 will not retroactively mark events as conversions, so set this up before traffic builds.

Common mistakes

  • Installing GA4 twice. One install via gtag.js directly and another via GTM, or two GTM tags pointing to the same property. This doubles your pageview and event counts. Check using DebugView — if you see two page_view events firing on each page load, you have a duplicate tag.
  • Using the wrong property for the wrong site. It sounds obvious but connecting your live site to a test property, or vice versa, is a common mistake when multiple properties exist in the same account.
  • Not filtering internal traffic. If your team visits the site regularly, your session counts, bounce rates, and conversion rates are all being distorted by internal traffic. Filter it out from day one.
  • Not setting data retention to 14 months. The 2-month default means you lose exploration data for any date range older than 2 months. This cannot be recovered retroactively.
  • Assuming installation equals tracking. Installing the GA4 tag gives you automatic page views and basic enhanced measurement. It does not give you custom event tracking, conversion tracking, or meaningful engagement data. Those require additional configuration in GTM.
AB
Abhinav Bhargav
Founder, MetricByte Consulting · Adobe Certified Master — Analytics Architect

8 years implementing and auditing analytics programs across Adobe Analytics, AEP, GA4, and GTM for enterprise organizations. Founder of MetricByte Consulting. Connect on LinkedIn →