Setup Guide

Set up Google Analytics 4 as a destination in RudderStack.

Follow the below steps to set up Google Analytics 4 as a destination in RudderStack:

  1. From the list of destinations in RudderStack dashboard, select Google Analytics 4.
  2. Select an existing source from the displayed ones or set up a new source to connect to Google Analytics 4 and click Continue.

Connection settings

To successfully configure Google Analytics 4 as a destination, configure the following settings:

  • Name: Assign a name to your destination.

  • API Secret: Enter the API Secret generated through the Google Analytics dashboard. It can be created in the Google Analytics dashboard under Admin > Data Streams > Choose your stream > Measurement Protocol > Create.

  • Client Type: Select the client type as gtag or Firebase from the dropdown:

    • gtag - Supported for both cloud and device mode. If you select gtag, enter the following:
      • Measurement ID: Enter the Measurement ID which is the identifier for a data stream. It can be found in the Google Analytics dashboard under Admin > Data Streams > Choose your stream > Measurement ID.
    • Firebase - Supported only for cloud mode. If you select Firebase, enter the following:
      • Firebase App Id: Enter the Firebase App ID which is the identifier for Firebase app. It can be found in the Firebase dashboard under Project Settings > General.

Refer to the FAQ section for more information on how to obtain the API secret, Measurement ID, and Firebase App ID.

  • SDK Base URL: Enter the custom domain you want to use as the native SDK’s base URL. RudderStack loads the gtag.js in the {SDK_Base_URL}/gtag/js?id=${measurementId} format. The default value for the SDK base URL is https://www.googletagmanager.com/.

Connection compatibility

Destination info
  • Status: Generally Available
  • Supported sources: Android, iOS , Web, Unity, AMP , Cloud, React Native , Flutter, Cordova, Warehouse, Shopify
  • Refer to it as GA4 in the Integrations object.

Connection modes
SourceCloud modeDevice modeHybrid mode
AMPsupportednot supportednot supported
Androidsupportedsupportednot supported
Cloudsupportednot supportednot supported
Cordovasupportednot supportednot supported
Fluttersupportednot supportednot supported
iOSsupportedsupportednot supported
React Nativesupportednot supportednot supported
Shopifysupportednot supportednot supported
Unitysupportednot supportednot supported
Warehousesupportednot supportednot supported
Websupportedsupportedsupported
Supported message types
SourceIdentifyPageTrackScreenGroupAlias
Cloud mode
Supported sourcesnot supportedsupportedsupportednot supportedsupportednot supported
Device mode
Androidsupportednot supportedsupportedsupportednot supportednot supported
iOSsupportednot supportedsupportedsupportednot supportednot supported
Websupportedsupportedsupportednot supportedsupportednot supported
info
In web device mode integration, that is, using JavaScript SDK as a source, RudderStack loads the Google Analytics 4 native SDK from https://www.googletagmanager.com/ domain. To load the native SDK from a custom domain, use the SDK Base URL setting in the RudderStack dashboard. Based on your website’s content security policy, you might need to allowlist this domain to load the Google Analytics 4 SDK successfully.

Connection mode comparison: hybrid vs. cloud vs. device

The following table lays out a detailed comparison to help you choose a connection mode:

info

Note that:

  • RudderStack makes the primary decision on how to track and stitch events together based on the client_id and session_id parameters.
  • Server-side session tracking supports only a subset of user dimensions. Google’s Measurement Protocol API does not support the reserved fields like location, demographics, predefined user dimensions, and device-specific information.
Device modeCloud modeHybrid mode with client ID override (RECOMMENDED)Hybrid mode without client ID override (Requires SDK configuration)
DescriptionRudderStack’s SDK loads the native client libraries.Sends data server-side to Google’s Measurement Protocol API.Automatically configures a single connection that captures attribution data from page calls (sent via device mode) and all other calls via cloud mode.Automatically configures a single connection that captures attribution data from page calls (sent via device mode) and all other calls via cloud mode.
Client IDFetches the client_id automatically generated by gtag.You can send a custom client_id via externalID. Otherwise, RudderStack sends an anonymousId or rudderId. See Mapping client_id.Overrides the client_id with RudderStack’s anonymousID. (RudderStack utilizes a cookie that adds an rs_ prefix to the existing Measurement ID)Fetches the client_id automatically generated by gtag.
Session IDFetches the session_id automatically generated by gtag.Passes session_id automatically but you can customize it using these mappings.Overrides session_id with the RudderStack’s session_id.Fetches the session_id automatically generated by gtag.
ConsiderationsOffers full information capture but it’s worth noting potential impacts the performance, page speed, data resilience, and first-party data capture.Google’s Measurement Protocol doesn’t support passing certain reserved fields, including attribution data.Introducing a custom client_id may cause fragmentation in multi-domain implementations. You may observe a potential momentary spike in session count while switching from device mode initially.Buffer the SDK with a slight delay to avoid a potential race condition whereby the SDK events reach GA4 prior to the events sent via server-side.
Required actionsNATo capture full attribution data, you must pass it as custom dimensions or instrument a parallel client-side integration.Ensure that the override setting is enabled in the RudderStack dashboard. To ensure accurate cross-platform analytics, check that other cookies (such as Google Ads) also include the appropriate rs_ prefix.Instrument your SDK to buffer.

For example:
rudderanalytics.load(
"write_key",
"dataplane_url",
{
bufferDataPlaneEventsUntilReady: true
}
);

Configuration settings

In the Configuration tab of your destination, you can configure the below-mentioned cloud and device mode settings:

Cloud mode

  • Debug via Validation Server: Enable this setting to check the validation responses in the Live Events tab. Debug mode is supported via GA4’s validation server endpoint.
warning
As per the GA4 documentation, any responses sent to the validation server will not show up in the reports.
  • Filter user traits: Enter the list of user traits which you do not want RudderStack to send to GA4. You can use this field to filter sensitive PII fields like email, phone number, credit card number, etc. from your events and prevent them from being sent to GA4.
info

Note that:

Device mode

  • Filter user traits: Enter the list of user traits which you do not want RudderStack to send to GA4. You can use this field to filter sensitive PII fields like email, phone number, credit card number, etc. from your events and prevent them from being sent to GA4.
info
To specify multiple traits, press the enter key after each trait.
  • Choose how to capture pageviews: Select RudderStack JS SDK or gtag Automated Capture from the dropdown depending on whether you want to send the page view events through the RudderStack JS SDK, or through automatic collection on each page load using GA4 Enhanced Measurement (gtag) respectively. See GA4 documentation for more information.
  • Debug via DebugView: This setting lets you monitor the device mode events in DebugView. It displays the events and user properties that GA4 collects in realtime. With this feature, you can troubleshoot issues as you install your tags or go through a user’s live activity.
  • Include URL and Search as Page View properties: Enable this setting to send the following properties along with any other custom property to the page call of the RudderStack SDK:
    • url
    • search
info
Google Analytics 4 has a limit on the number of unique properties per event name. The default page_view event supports the properties mentioned in the Automatically collected events in Google Analytics 4 guide.

Hybrid mode

  • Debug via Validation Server: If you enable this setting, then RudderStack sends the cloud mode events (track and group calls) to the GA4 validation server. These events will not show up in your reports.
  • Filter user traits: Enter the list of user traits which you do not want RudderStack to send to GA4. You can use this field to filter sensitive PII fields like email, phone number, credit card number, etc. from your events and prevent them from being sent to GA4.
info
To specify multiple traits, press the enter key after each trait.
  • Choose how to capture pageviews: Select RudderStack JS SDK or gtag Automated Capture from the dropdown depending on whether you want to send the page view events through the RudderStack JS SDK, or through automatic collection on each page load using GA4 Enhanced Measurement (gtag) respectively. See GA4 documentation for more information.
  • Debug via DebugView: If this setting is enabled, then the device mode events (page calls) will be visible under the GA4 DebugView section.
  • Include URL and Search as Page View properties: Enable this setting to send the following properties along with any other custom property to the page call of the RudderStack SDK:
    • url
    • search
  • Override gtag client ID & session ID: Enable this setting to override the gtag client_id and session_id with RudderStack’s anonymousId and session_id to ensure that the attribution is properly unified across the page and track events.
warning

If you are transitioning to the GA4 hybrid mode from device mode, enabling this setting could lead to a momentary spike in session counts. To avoid this scenario, disable this setting and buffer the SDK instead.

For all other scenarios, you can enable this setting.

Other settings

  • Choose if you want to turn on events filtering: This option is applicable only if you’re sending events to Google Analytics 4 via web device mode. See Client-side Event Filtering for more information. | Consent management settings | Configure the consent management settings for the specified source by choosing the Consent management provider from the dropdown and entering the relevant consent category IDs. See Consent Management in RudderStack for more information on this feature. |

FAQ

How do I obtain the Measurement Id?

  1. Log in to the Google Analytics dashboard.
  2. Go to the Admin section in the left sidebar.
  3. Select the relevant account and property.
  4. Click Data Streams and select the stream to get the Measurement Id:

How do I obtain the API Secret?

  1. Login to Google Analytics dashboard.
  2. Go to the Admin section in the left sidebar.
  3. Select the relevant account and property.
  4. Click Data Streams and select the stream.
  5. Click Measurement Protocol API secrets to get the API Secret:

How do I obtain the Firebase App ID?

  1. Login to Google Analytics dashboard.
  2. Go to the Admin section in the left sidebar.
  3. Select the relevant account and property.
  4. Click Data Streams and select the stream to get the Firebase App Id:

How can I prevent RudderStack from sending PII fields to Google Analytics 4?

To prevent RudderStack from sending sensitive PII data in your events to GA4, specify the user traits in Filter user traits while configuring your destination settings.

info
To specify multiple traits, press the enter key after each trait.


Questions? Contact us by email or on Slack