To set up Google Analytics 4 (GA4) in Google Tag Manager, you need to configure the Google tag. The Google tag enables data to flow from your website to Google Analytics and any other designated destinations. Ensure you create a unique Google tag for each website. For additional instructions on setting up Google Analytics, refer to Set up Analytics.
How the Google tag works
The Google tag works by loading your Google Analytics property on a page and:
- Declaring common settings for Google Analytics tags
- Setting Google Analytics cookies
- Sending automatically collected and enhanced measurement events
Before you begin
This guide assumes that you've done the following:
- Create a Google Analytics 4 account and property
- Create a web data stream for your website
- Set up Tag Manager
It also assumes that you have the following:
- Access to the Tag Manager container for the website
- The Editor (or above) role to the Google Analytics account
Set up the Google tag
- Go to https://tagmanager.google.com.
- Sign in to your Google Account. Learn how to create a Google Account.
- In Tag Manager, click the Accounts tab (top left), then select your container. Find your way around Tag Manager.
- In the Workspaces tab, go to Tags, then click New (top right).
- In the panel, follow these steps:
- Replace Untitled Tag with the name of your tag (for example, 'Google tag').
- In the Tag Configuration section:
- In Choose tag type, select Google Tag.
- In Tag ID, enter your Tag ID. Learn how to find your Tag ID.
- Optional: You can set up additional configuration options to govern how your Google tag communicates with its destinations. If you set up the Google tag and want to keep all its default settings, you can skip the optional settings.
Optional settings
Global parameter settings
If you need to establish common context across several Google tags, you can specify global parameters using gtag.js directly on your website.
Global parameters are read by all Google tags on your website. Use this option only for non-sensitive data.Learn how to reuse parameters across multiple tags, in the developer documentation.
Configuration settings
You can specify additional configuration parameters that influence the Google tag settings.
To reuse configuration across Google tags, create a configuration settings variable.
Shared event settings
You can specify additional parameters that are sent with every event, for example the
currency
of a price. Event parameters are only valid for the tag you add them to.To reuse event settings across Google tags, create an Google Tag Event Settings variable. Use recommended event parameter names so that Google Analytics can populate dimensions and metrics for you.
Send data to a tagging server
Server-side tagging allows you to move some tags off of your website or app and onto a server instead, which allows you to improve performance. Learn more about server-side tagging.
To send all events to a Tag Manager server container instead of Google Analytics, you need to configure the following parameter:
- Open the Configuration settings menu.
- Set up the server container URL by adding a new configuration parameter:
- Name:
server_container_url
- Value: Set to the server container URL of your Tag Manager server container
- Name:
Result: Your configuration parameters should look like this:
Set up user properties
User properties are attributes that describe groups of your user base, such as their language preferences or geographic locations. You can use user properties to define audiences.
For example, you can set a user property called
favorite_food
, which you can use to record each user's favorite food. You can use the data to segment users by their favorite food.Analytics automatically collects some user dimensions so you don't have to define user properties for them. You can set up to 25 additional user properties per Google Analytics 4 property.
To measure custom user properties you need to create a new Google Tag Event Settings variable and then assign it to the Google tag.
- In the Triggering section, select Initialization - All Initialization Events or Some Initialization Events. Learn more about Page view triggers.
- Click Save.
Verify and publish
Verify
- Go to https://tagmanager.google.com.
- Sign in to your Google Account. Learn how to create a Google Account.
- Open the Tag Manager container you want to edit. Find your way around Tag Manager.
- In the Workspace tab, click Preview (top right) to launch Google Tag Assistant in a new tab.
- Enter your website URL and click Connect. Learn to debug with Tag Assistant.
Publish
- In the Workspace tab, click Submit (top right)
- In the Submission Configuration section, follow these steps:
- Select Publish and Create Version to publish the changes to your site. To save the changes without publishing them, select Create Version instead.
- Enter a name and description for the version.
- Select Activity History to review the changes you've made since the previous version.
- Click Publish (top right).