How to Configure Tracking with GA4 and Google Tag Manager

This post discusses the transition and configuration with Google Analytics (GA4) and Google Tag Manager (GTM)

How to Configure Tracking with GA4 and Google Tag Manager

I’ve used Google Analytics for a long time and it’s been great. However, with the transition to GA4, some changes made me look at our configuration again.

Back to Basics

The following are the basic ideas and terms used throughout this post:

  • Tag
    • Small piece of executable code that allows you to send events from your site to Google product destinations
  • Google Analytics (GA)
    • A tool for tracking web/app usage and events
  • Google Tag Manager (GTM)
    • A tool for managing dynamic tags
    • Allows you to deploy shim code to your site and add more tags dynamically without requiring changes
    • Required for 3rd party tags
  • gtag
    • a single tag (gtag != GTM)
    • Can be deployed directly or via GTM
    • Google Analytics will provide gtag code (via the data stream), however, it is recommended to use GTM for the flexibility
    • I’ll cover how to link a GTM tag event to a GA4 data stream id
  • Account
    • A bucket for the business/organization
    • Depending on the company, it is common to have a single account
  • Property
    • A site (app/web) or set of sites
    • Used as a bucket for consolidating tracking and analytics
    • Streams in a property should “make sense” and not aggregate things that should be looked at differently
  • Data Stream
    • A mechanism to break down and track data flowing into a single property
    • For example, if you had a web app and mobile app, those could both be data streams on the same property
    • If you had a variety of marketing sites and wanted consolidated reporting, those would be data streams on the same property
  • Universal Analytics (UA)
    • The older version of Google Analytics
    • Replaced by GA4
    • Will deprecate on July 1, 2024
  • Google Analytics 4 (GA4)
    • The newer version of Google Analytics
    • Recommended to use

How to structure your properties

When thinking about how to structure your properties, there are a lot of options:

  • Single property for all (1:*)
    • For this approach, you’d have a single property for all properties and a data stream per site
    • This will make consolidating things easy, however, you have to drill down to look at individual properties
  • Property per logical group of properties (1:n)
    • In this approach, you have a property per logical group of properties where it makes sense
    • For example, you’d want your marketing sites to likely be all in the same property to allow you to view all marketing site traffic
    • In this scenario, each site would be its own data stream within this property
  • Property per site (1:1)
    • In this approach, you have a property per site
    • This does make some aggregations difficult as these are all at the property level

So what should you do? Use the property per logical group of properties approach.

Here’s how we’ve structured our properties:

  • marketing sites (property)
    • devrev.ai (data stream)
    • marketplace.devrev.ai
    • onecrm.ai
    • (future marketing sites)
  • docs.devrev.ai
    • docs.devrev.ai
    • (future docs sites)
  • app.devrev.ai
    • app.devrev.ai
    • (future app sites)
  • thebook.devrev.ai
    • thebook.devrev.ai
    • (future thebook sites)

How to configure

The following video shows how to configure the following:

  • Create a new data stream on a property
  • Create a new GTM container
  • Create tags in the GTM container for the data stream
  • Configure GTM events to be sent to the Google Analytics

TL;DR

  • Use GTM instead of gtag for the flexibility
  • Create a property for each bucket of properties
  • Create data streams for each site in the property
essential