[GA4] Implementation guide for Google Tag Manager

This article is for website owners who want in-depth implementation guidance. It assumes that you have already created a Google Analytics 4 property. If you just want to add basic measurement to your page, read this article instead. 
In this article:

Enable basic data collection

To enable basic data collection of events (including pageview and other automatic and enhanced measurement events) for a web data stream, you'll need to deploy the Google Analytics: GA4 Configuration tag to every page that needs to be measured. The tag initializes Google Analytics for your property, sets Google Analytics cookies, and sends automatic and enhanced measurement events (including pageviews).

To create a GA4 Configuration tag:

  1. Click Tags and then New.
  2. Click Tag Configuration.
  3. Select Google Analytics: GA4 Configuration.
  4. Enter your measurement ID.
  5. Optional: Add any parameters you'd like to configure in Fields to Set. Use recommended event parameter names for best results.
  6. Optional: Add any custom user properties that you'd like to configure in User Properties. Note: Analytics automatically logs some user properties. You can set up to 25 additional user properties per Google Analytics 4 property.
  7. Optional: Use Advanced Settings to set a Tag Firing Priority or use Tag Sequencing to help ensure that the Configuration tag fires before any other event tags that require it.
  8. Click Triggering and select appropriate triggers that would cause the tag to fire, e.g. "All Pages", so that the configuration tag fires on all pages of your website.
  9. Save the tag configuration and publish your container.

Events

In a Universal Analytics property implemented via gtag.js ("UA-XXXXXXXX"), events are implemented as a separate hit type, using the dimensions Event Category, Action, and Label and the metric Event Value. When collected, they appear in your reports and there are no limits to the number of different event, dimension and metric values.

In a Google Analytics 4 property, every "hit" is an "event," meaning there is no longer a distinction between hit types.

Types of events in a Google Analytics 4 property

Google Analytics 4 events fall into four categories: automatically collected events, enhanced measurement, recommended events, and custom events.

  1. Automatically collected events are collected automatically with basic data collection.
  2. Enhanced measurement provides events that you can toggle on and off using the Admin interface within a Google Analytics 4 property. Enhanced measurement events DO NOT REQUIRE adding/modifying code on web or in app
    • Note that when events are/remain implemented as individual events and are also collected via enhanced measurement, those events will be logged twice. If you are sending an event to both a Universal Analytics and a Google Analytics 4 property, the solution is to add a "send_to" parameter in the event specifying the relevant Universal Analytics property ID. That way, the event only flows to the Universal Analytics property and not to the Google Analytics 4 property.
    • Technical note: Enhanced measurement is not based on HTML ID’s or classes, unlike situations where you have used HTML ID’s and classes as triggers or variables for events such as link clicks and downloads via Google Tag Manager.

  1. Recommended events are events that you manually implement, but that have Google-predefined names and parameters. Recommended events unlock existing and future reporting capabilities not available for custom events (events that you name yourself). Recommended events exist for:
  1. Custom events are events that you name and implement yourself.

Best practices when implementing events

  1. Wherever possible, use automatically collected and enhanced measurement events instead of implementing events yourself.
  2. If a desired event is not automatically collected and is not provided as part of enhanced measurement, look for a recommended event to implement.
  3. Implement a custom event only if (1) and (2) do not meet your needs.

Make an inventory of all the events that are being used in your Universal Analytics property and see if the automatically collected and enhanced measurement events can cover these needs for your Google Analytics 4 property. Focus on these events first as they do NOT have to be manually coded for migration.

Manually implemented events (i.e., recommended and custom events)

The data structure of events differs between Google Analytics 4 and Universal Analytics properties.

  • In a Universal Analytics property, events have “Event Category”, “ Event Action”, “ Event Label”, and “Event Value” fields and custom dimensions can be added.
  • In a Google Analytics 4 property, a manually implemented event consists of “Event Name”, automatically collected parameters, and manually specified parameters. These manually specified parameters replace the event fields from a Universal Analytics property, and they can also be used for specifying additional information with the event.

Add recommended events, custom events, and custom parameters

If you currently use Universal Analytics tags to collect any events that can be automatically collected via enhanced measurement, you should use the enhanced measurement events instead of manually instrumenting the events yourself. If the enhanced measurement events do not meet your needs, follow the steps below to set up Google Analytics 4 Event tags.

The Google Analytics 4 Event tag lets you send custom events to Analytics, in addition to the events that are sent automatically or through enhanced measurement. For example, if you want to collect more detailed scroll depth data than what is provided via enhanced measurement, you can trigger a Google Analytics 4 Event tag to fire based on Tag Manager’s scroll depth trigger.

To create a Google Analytics 4 Event tag:

  1. Click Tags and then New.
  2. Click Tag Configuration.
  3. Select Google Analytics: GA4 Event.
  4. For Configuration Tag, select the Configuration Tag you created earlier.
  5. For Event Name, specify the name of the event. Use the recommended event names for best results.
  6. Optional: Enter Event Parameters. Use recommended event parameter names for best results.
    1. Click Add Row.
    2. Enter a Parameter Name.
    3. Enter a Value.
    4. Repeat until all desired parameters have been added.
  7. Optional: Add any custom user properties that you'd like to configure in User Properties. Note: Analytics automatically logs some user properties. You can set up to 25 additional user properties per Google Analytics 4 property.
  8. Optional: Use Advanced Settings to set a Tag Firing Priority, or use Tag Sequencing to help ensure that the Configuration tag fires before any other event tags that require it.
  9. Click Triggering and select appropriate events that would cause the tag to fire.
  10. Save the tag configuration and publish your container.

Example Event tag configuration:

  • Event Name: scroll
  • Parameter Name: percent_scrolled
  • Parameter Value: {{Scroll Depth Threshold}} (populated by built-in variable)
Use Advanced Settings and then Tag Sequencing to specify that an Event tag should fire after a Configuration tag.

Follow the recommended event schema whenever possible when defining the event and parameter names. Example schema shown below; full schema here.

Event Trigger... Parameters
login when a user logs in. method
purchase when a user completes a purchase transactions_id, value, currency, tax, shipping, items, coupon
refund when a user receives a refund transactions_id, value, currency, tax, shipping, items
search when a user searches your content search_term
select_content when a user has selected content content_type, item_id
share when a user has shared content content_type, item_id
sign_up

when a user has signed up

Allows you to see which methods of sign-up (e.g., Google account, email address, etc.) are most popular

method

Additional implementation guidance

Tag types

Universal Analytics has only one tag type, whereas Google Analytics 4 has two tag types: the GA4 Configuration tag and GA4 Event tag.

  • The GA4 Event tag references the Configuration tag and therefore depends on the Configuration tag being set up.
  • At runtime, the Configuration tag must fire before the Event tag.

To ensure that the Configuration tag is fired before the Event tag, assign a Configuration tag trigger that is guaranteed to be earlier than the Event tag’s trigger.

Overlap with automatically collected parameters

Events in Google Analytics 4 properties automatically collect a number of event parameters by default for every event. These include:

  • language
  • page_location
  • page_referrer
  • page_title
  • screen_resolution

Additionally, automatically collected events also include a number of their own automatically collected parameters. It's possible that you collect some of these parameters as custom dimensions in your Universal Analytics property. For your Google Analytics 4 property, however, you should not manually specify these as parameters since they are automatically collected for you.

Custom dimensions/metrics

Universal Analytics custom dimensions and metrics map to Google Analytics 4 event parameters or user properties, depending on scope. You can carry over the custom dimensions/metrics from Universal Analytics tags to Google Analytics 4 tags as follows:

  • hit-scoped → assign to GA4 Event tag as events or event parameters
  • session-scoped → In Google Analytics 4 properties, there is no need for session-scoped as dimension and metric values largely map to user properties and events or parameters.
  • user-scoped → assign to GA4 Configuration tag as user properties, to assign to GA4 Event tag using the “user_properties” parameter in “Fields to Set”.
  • product-scoped → map to ecommerce parameters

Persist settings across events

Universal Analytics makes use of a “Google Analytics Settings” variable to persist tag settings (e.g. tracking ID, cookie domain, or disable advertising features) that need to be consistent across Universal Analytics tags. You can similarly persist settings across GA4 Event tags using the GA4 Configuration tag. GA4 Event tags inherit the parameters and user properties of the linked GA4 Configuration tag.

Interaction between on-page gtag.js code and Tag Manager GA4 tags

If you have both a gtag.js implementation and a Tag Manager GA4 implementation on the same page, the on-page gtag.js code may have an impact on the Tag Manager GA4 tags. Some settings parameters, such as “cookie_prefix”, or “allow_ad_personalization_signals”, assigned via the on-page gtag('set', paramName, paramValue) command will propagate the parameters to GA4 tags fired from Tag Manager.

Was this helpful?
How can we improve it?