Set up Google Analytics 4

Set up Google Analytics 4 as a destination in RudderStack.

RudderStack supports sending event data to Google Analytics 4 via the following connection modes:

Connection ModeWebMobileServer
Device ModeSupported--
Cloud ModeSupportedSupportedSupported
info
In a 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. Based on your website’s content security policy, you might need to allowlist this domain to load the Google Analytics 4 SDK successfully.

Once you have confirmed that the source platform supports sending events to Google Analytics 4, follow these steps:

  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.

Connection mode

Choose how to connect Google Analytics 4 to your source(s) by selecting from the cloud, device, or hybrid modes.

Further, click Continue and Configure your destination.

Configuration settings

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

Cloud mode

  • Enable debug mode: Enable this setting to check the validation responses in the Live Events tab. Debug mode is supported via the validation server endpoint. However, as per the GA4 documentation, any responses sent to the validation server will not show up in the reports.

Device mode

  • 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. Refer to the GA4 documentation for more information.

  • 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.
  • Add send_to parameter in gtag event call: Enable this setting to send an event only to the specific Google Analytics 4 property whose Measurement Id you have specified above. When enabled, a sample event to Google Analytics 4 looks as shown:
gtag('event', 'view_video', { 'send_to': '<property_id>' }); // where <property_id> is the measurement id of the GA4 data stream.

Refer to the Google documentation for more information on send_to parameter.

  • 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. Refer to the Client-side Event Filtering guide for more information.

  • Cookie category name: This setting lets you associate the OneTrust cookie consent groups to Google Analytics 4.

Hybrid mode

Hybrid mode sends your event data to Google Analytics 4 via both the native SDK (device mode) and the Google Analytics 4 Measurement Protocol (cloud mode).

Why hybrid mode?

Unlike GA Universal, GA4’s server-side tracking (cloud mode) is less independent and may require support from client-side tracking (device mode). As noted in Google’s docs, Measurement Protocol is meant to augment automatic collection via gtag, Tag Manager, and Google Analytics, not replace them.

Through a single hybrid mode deployment, you would have access to a fuller, more unified and accurate set of attribution data with the least impact on performance—resulting from a combination of client-side and server-side tracking. Specifically, a hybrid instrumentation may make sense for those who prefer to maintain the benefits of cloud mode—including a faster site, more reliable data collection, and first-party data capture, while also capturing data required for attribution, sessionization, geolocation, and conversions for Google Ads Remarketing.

Use hybrid mode

To use GA4 connection in hybrid mode, you can select the Hybrid mode while setting up the connection modes. This option is available only for the gtag.js web SDK.

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:

Questions? Contact us by email or on Slack