Set up Google Analytics 4 as a destination in RudderStack.
6 minute read
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.
In your RudderStack dashboard, add a source. Then, from the list of destinations, select Google Analytics 4 (GA4) v2.
Connection settings
Setting
Description
Name
Assign a name to uniquely identify your destination.
oAuth settings
Click Create Account and connect RudderStack with your Google Analytics account. Then, choose the account and click Save to proceed.
Protocol secrets
RudderStack automatically populates your GA4 protocol secret. In case you have set up multiple data streams, choose the relevant protocol secret from the dropdown.
Connection mode
Specify how you want to route the events from your source to Google Analytics 4.
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.
The mappings specified in this section take precedence over any other event transformation applicable for the destination.
Then, configure the below settings depending on your connection mode:
Cloud mode settings
Setting
Description
Debug via Validation Server
Turn on this setting to check the validation responses in the Live Events tab. RudderStack supports the debug mode via GA4’s validation server endpoint.
Enter 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.
Consent management provider
Configure the consent management settings for the specified source by choosing the consent management provider from the dropdown.
Turn 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 traits
Enter 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 pageviews
From 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 DebugView
If 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 properties
Turn 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 ID
Turn 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 filtering
Specify 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.
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.
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 ID
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 ID
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.
Considerations
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 actions
To 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.
This site uses cookies to improve your experience while you navigate through the website. Out of
these
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
essential
for the working of basic functionalities of the website. We also use third-party cookies that
help
us
analyze and understand how you use this website. These cookies will be stored in your browser
only
with
your
consent. You also have the option to opt-out of these cookies. But opting out of some of these
cookies
may
have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
This site uses cookies to improve your experience. If you want to
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.