Instrumentation updates for the GA4 hybrid mode integration.
Available Plans
free
starter
growth
enterprise
2 minute read
What changed?
We have updated our GA4 hybrid mode implementation to include 2 options for instrumentation. You can now either:
Override the clientID & sessionID with a RudderStack ID, or
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.
In your configuration settings in the RudderStack dashboard, make sure that you select Hybrid mode for your GA4 connection mode.
Toggle on the Override gtag client ID & session ID setting in your Web SDK configuration settings.
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.
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.
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.