How to Send Data to GA4 Hybrid Mode
You can set up our GA4 integration in three different connection modes: cloud mode, device mode, or hybrid mode. Hybrid mode enables you to easily send events through both cloud mode (server-side tracking) and device mode (client-side tracking) to GA4. In this guide, we’ll show you how to set up GA4 as a destination in RudderStack along with the different configuration options available:
Step 1. Set up an SDK source
RudderStack supports more than 15 SDK and cloud app sources for real-time event ingestion. In this example we’ll set up a Javascript source by choosing Javascript from our source directory. To ensure the SDK Source is successfully ingesting events, we’ll click the Live Events button to view the events sent from the source in real-time.
Step 2. Set up a GA4 destination
Now that the source is set up, we can connect it to a destination from the overview tab of the source. We’ll choose GA4 from the destination directory.
At this point, we’ll have to provide our connection settings by entering our Measurement ID and the Measurement API. The Measurement ID and Measurement API secret are found on the Web stream details page after creating a property in GA4.
Next, we’ll choose the connection mode. Here, we have three options:
- Device mode only
- Cloud mode only
- Hybrid mode (both cloud and device mode)
For this example, we’ll set things up in Hybrid mode. If you’re interested in setting up a connection in cloud or device mode only, check out this guide on Getting Started with Google Analytics 4.
What happens in Hybrid mode:
Choosing the Hybrid mode option divides events into two streams:
- Device mode captures Page events.
- Cloud mode captures Track, Screen, and Identify events.
On the RudderStack backend, we grab the session ID and client ID from gtag events sent through device mode and merge them with events captured through cloud mode to build accurate and full reporting of user interactions within that session.
Step 3. Configure the GA4 destination and test your connection
Once we select Hybrid mode, we’ll move on to the next step which will have the destination configurations. Here we have a few important selections to make:
GA4 IT / Debug Mode
Here we can enable debug mode to send any error messages to the Google Measurement Protocol validation server. If an error occurs and the event fails or is malformed, the error will show up in the Live Events viewer with this toggled on. When using debug mode, it’s important to remember:
- The validation server validates that your events have the correct structure, but to verify that they are being sent correctly to your property, you'll need to verify your implementation.
- When debug mode is on, events are sent to the validation server and do not show up in the GA4 report.
Web SDK configuration
Here we’ll first choose how to capture page views:
- RudderStack JS SDK: Captures page views using RudderStack page calls
- Gtag automated capture: Captures page views using gtag’s enhanced measurement, which is how GA4 natively captures page visits
If you want to manually choose how and when page views are sent, select the first option and instrument page calls on the respective pages where they need to be made.
Next, we’ll choose whether or not to 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
Finally, we’ll decide if we want to Override gtag session_id with the RudderStack session_id. Toggle this to ensure you have the same session_id across device and cloud mode. This is necessary when using Hybrid mode.
Once settings are all configured, we’ll use the toggle to enable this destination, and then we can start testing our events using the Live Events viewer. Note that page calls may show up as errors because we are blocking incoming page calls through cloud mode and sending them through device mode instead. So while it may appear there is an error, these calls are being processed and sent to GA4.
The final step is to verify our hybrid implementation. If we check the GA4 real-time analytics dashboard we should be able to see the events (page and track) flow in along with any geolocation data or UTM parameters they may carry. This is a capability that wasn’t possible before with only cloud mode.
With just a few simple steps, we have our GA4 destination setup in hybrid mode, capturing fuller, more reliable events that give better insight to user interactions.