GA4 Hybrid Mode Updates

Instrumentation updates for the GA4 hybrid mode integration.
Available Plans
  • free
  • starter
  • growth
  • enterprise

What changed?

We have updated our GA4 hybrid mode implementation to include 2 options for instrumentation. You can now either:

  1. Override the clientID & sessionID with a RudderStack ID, or
  2. Incorporate a JS SDK buffering option.

Why did we build this?

The GA4 hybrid mode solution works by sending page calls via device mode and all other events via cloud mode. These events need to be stitched together, relying on clientID and sessionID to send complete event data.

In our original implementation, we fetched the clientID and sessionID from gtag.js. Soon we discovered that sending the data this way led to a race condition whereby events sent via cloud mode were potentially reaching GA4 in advance of events sent device mode—which meant that events would not be properly stitched together.

How does it work?

Option 1 [recommended]: Override the clientID and sessionID with the RudderStack ID.

In this option, RudderStack overrides the client ID with the RudderStack anonymousID. This means that we utilize a generated cookie that adds an rs_ prefix to the existing Measurement ID. Similarly, RudderStack overrides the session ID with the RudderStack session ID.

  1. In your configuration settings in the RudderStack dashboard, make sure that you select Hybrid mode for your GA4 connection mode.

  2. Toggle on the Override gtag client ID & session ID setting in your Web SDK configuration settings.

GA4 ID override setting
If you are switching from device mode, there may be a momentary spike in session counts as a result of this changeover. To ensure accurate cross-platform analytics, be sure to check that other cookies (such as Google Ads) include the appropriate rs_ prefix.

Option 2: Instrument a buffer in the JS SDK.

In this option, RudderStack fetches both the clientID and sessionID from gtag.js. In this scenario, however, you must instrument a custom snippet within the JS SDK to buffer, that is, delay events by ~2 seconds in order to ensure that device and cloud mode events are stitched together, avoiding the race condition.

Incorporate the following snippet in your SDK:

rudderanalytics.load( "write_key", "dataplane_url", { bufferDataPlaneEventsUntilReady: true } )
This means there could be a ~2 second delay in events being sent (though those events will be queued to prevent event data loss). Also note that this buffering occurs on client side, with a 10 second timeout, meaning that any events which are not able to reach GA4 after 10 seconds will be dropped.

See our GA4 hybrid mode documentation for further details on this integration.

Questions? Contact us by email or on Slack