Set up Google Analytics 4

Set up Google Analytics 4 as a destination in RudderStack.

This guide will help you set up Google Analytics 4 as a destination in the RudderStack dashboard. It also lists the configuration settings required to correctly send data from the supported sources to Google Analytics 4.

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_V2 in the Integrations object.

Connection modes
SourceCloud modeDevice modeHybrid mode
AMPsupportednot supportednot supported
Androidsupportednot supportednot supported
Cloudsupportednot supportednot supported
Cordovasupportednot supportednot supported
Fluttersupportednot supportednot supported
iOSsupportednot supportednot supported
React Nativesupportednot supportednot supported
Shopifysupportednot supportednot supported
Unitysupportednot supportednot supported
Warehousesupportednot supportednot supported
Websupportednot supportedsupported
Supported message types
SourceIdentifyPageTrackScreenGroupAlias
Cloud mode
Supported sourcesnot supportedsupportedsupportednot supportedsupportednot supported
Hybrid mode
Supported sourcesnot supportedsupportedsupportednot supportedsupportednot supported

Setup

In your RudderStack dashboard, add a source. Then, from the list of destinations, select Google Analytics 4 (GA4) v2.

Connection settings

SettingDescription
NameAssign a name to uniquely identify your destination.
oAuth settingsClick Create Account and connect RudderStack with your Google Analytics account. Then, choose the account and click Save to proceed.
Protocol secretsRudderStack automatically populates your GA4 protocol secret. In case you have set up multiple data streams, choose the relevant protocol secret from the dropdown.
Connection modeSpecify how you want to route the events from your source to Google Analytics 4.

See the Connection mode comparison section for help.

Configuration settings

Configure the below settings to receive your data correctly in Google Analytics 4:

Custom mappings

RudderStack supports mapping your track events (including Ecommerce events) and associated properties to specific GA4 dimensions and metrics. See the Custom Mappings guide for more information on setting up these mappings.

info
The mappings specified in this section take precedence over any other event transformation applicable for the destination.
Set up custom mappings in GA4

Then, configure the below settings depending on your connection mode:

Cloud mode settings

SettingDescription
Debug via Validation ServerTurn on this setting to check the validation responses in the Live Events tab. RudderStack supports the debug mode via GA4’s validation server endpoint.

Note: As per the Google Analytics 4 documentation, any responses sent to the validation server will not show up in the reports.
Filter user traitsEnter the list of user traits you do not want RudderStack to send to GA4. You can use this field to filter sensitive PII fields from your events, like email, phone number, credit card number, etc., and prevent RudderStack from sending them to GA4. You can add multiple traits by pressing the enter key after specifying each trait.

Note: This setting is applicable only for the events that are not mapped in custom mappings.
OneTrust consent settingsEnter the category IDs for associating the OneTrust cookie consent groups to Google Analytics 4.
Ketch consent purpose settingsEnter the purpose IDs for associating the Ketch purposes to Google Analytics 4.

Hybrid mode settings

SettingDescription
Debug via Validation ServerTurn on this setting to send the cloud mode events (track and group) to the GA4 validation server. Note: These events will not show up in your reports.
Filter user traitsEnter the list of user traits you do not want RudderStack to send to GA4. You can use this field to filter sensitive PII fields from your events, like email, phone number, credit card number, etc., and prevent RudderStack from sending them to GA4.

Note: You can add multiple traits by pressing the enter key after specifying each trait.
Choose how to capture pageviewsFrom the dropdown, select RudderStack JS SDK or gtag Automated Capture depending on whether you want to send the page view events through the RudderStack JavaScript SDK or through automatic collection on each page load using Enhanced Measurement (gtag) respectively.
Debug via DebugViewIf you turn on this setting, then the device mode events (page calls) will be visible under the GA4 DebugView section.
Include URL and Search as page view propertiesTurn on 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 IDTurn on this setting to override the gtag client_id and session_id with RudderStack’s anonymousId and session_id, ensuring that the attribution is properly unified across the page and track events.

Note that:
  • 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.
  • Turning on this setting will permanently reset your user metrics (new vs returning users).
Events filteringSpecify which events should be blocked or allowed to flow through to GA4 by selecting any of the below options from the dropdown:

  • No events filtering: RudderStack disables this feature - all the events flow through to GA4 as usual.
  • Filter via allowlist: Specify the Allowlisted events. RudderStack allows only these events to flow through to GA4.
  • Filter via denylist: Specify the Denylisted events. RudderStack blocks these events and allows the rest to flow through to GA4.

Connection mode comparison

The following table lays out a detailed comparison to help you choose a connection mode when sending events to Google Analytics 4.

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.
Cloud mode
Hybrid mode with client ID override

(Recommended)
Hybrid mode without client ID override

(Requires SDK configuration)
DescriptionSends 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 IDYou 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 IDPasses 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.
ConsiderationsGoogle’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 actionsTo capture full attribution data, you must pass it as custom dimensions or instrument a parallel client-side integration.Ensure that the Override gtag client ID & session ID setting is enabled in the RudderStack dashboard. To ensure accurate cross-platform analytics, check that other cookies (like Google Ads) also include the appropriate rs_ prefix.Instrument your SDK to buffer.

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

FAQ

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

You can prevent RudderStack from sending sensitive PII data in your events to GA4 by specifying the user traits in the Filter user traits configuration setting.

You can add multiple traits by pressing the enter key after specifying each trait.



Questions? Contact us by email or on Slack