Google Analytics 4
Segment has two GA4 destinations, the Google Analytics 4 Web Destination and the Google Analytics 4 Cloud Destination. The Google Analytics 4 Web destination can only be connected to website front-end Segment sources. When enabled, Segment will load the gtag.js library for you and sends tracking events to GA4 via gtag.js. The Google Analytics 4 Cloud destination can be connected to any Segment source, and sends tracking events directly to Google’s Measurement Protocol API.
We recommend configuring two GA4 Segment destinations to capture events from both the website front-end, which sends events for browsing activity, and from Chord's server source, which sents events for transactions in the OMS. This will give you the fullest picture of user activity in GA4.
Add a Google Analytics 4 Cloud Destination destination and connect to your Chord server source. Be sure to enter your Measurement ID and API Secret in the destination settings.
To send Segment events to GA4 events, we need to add mappings. Select Add Mapping in the destination configuration to add pre-built mappings and actions. The following pre-built mappings are supported by the Chord server source:
- Begin Checkout maps to Chord’s Checkout Started
- Purchase maps to Chord’s Order Completed
- Refund maps to Chord’s Order Refunded
The default mappings for the Google Analytics 4 Cloud destination do not include the enough data for GA4 to be able to connect the events to website front-end activity. There are two additional event mappings you can add to fix this, the Google Client ID and the user's ID.
Client ID
To tie together front-end and server Segment events as one session within GA4, you can send the Gtag-generated Client ID from the front end as the Client ID with the server events. Chord includes the Gtag-generated Client ID from the front-end on server events as the property integrations.Google Analytics.clientId.
To sent the Client ID to GA4, edit each mapping and find the Client ID property. It is blank by default:
Select the text input to the left, and in the Event Variables search bar, enter the text integrations.Google Analytics.clientId. Unless you have test data loaded, it will likely say "Not matches found," which is fine. Select Use "integrations.Google Analytics.clientId" as an event variable:
Now you should see this:
If events throw "Client ID is required for web streams" errors, it is because the destination requires a Client ID for all events. This is happening because the corresponding session must not have had front end events with a synced Client ID. To remedy this, you can use Segment's coalesce function to fall back to the userId, similar to what the destination would have used by default, as documented here.
User ID
Optionally, you can send the Segment user ID, which is typically the user or customer ID from the OMS, to GA4 with every event for an authenticated user. (The user ID is not available for guest activity.) This allows GA4 to connect user behavior across sessions and devices.
To sent the user ID to GA4, edit each mapping and find the User ID property. It is blank by default. Select the text input to the left, and in the Event Variables search bar, enter the text userId. Now you should see:
Add a Google Analytics 4 Web destination and connect to your website front-end source.
Select Add Mapping in the destination configuration to add pre-built mappings and actions. The following pre-built actions can be added without any adjustment to the mappings, if Chord is sending the corresponding event to Segment:
- Add to Cart maps to Chord’s Product Added
- Search maps to Chord’s Products Searched
- Select Item maps to Chord’s Product Clicked
- View Item List maps to Chord’s Product List Viewed
- Sign Up maps to Chord’s Signed Up
- View Cart maps to Chord’s Cart Viewed
- Purchase maps to Chord’s Order Completed
- View Promotion maps to Chord’s Promotion Viewed
- Add to Wishlist maps to Chord’s Product Added to Wishlist
- Remove from Cart maps to Chord’s Product Removed
- Select Promotion maps to Chord’s Promotion Clicked
- View Item maps to Chord’s Product Viewed
- Begin Checkout maps to Chord’s Checkout Started
- Login maps to Chord’s Signed In
Optionally, you can send the Segment user ID, which is typically the user or customer ID from the OMS, to GA4 with every event for an authenticated user. (The user ID is not available for guest activity.) This allows GA4 to connect user behavior across sessions and devices.
To sent the user ID to GA4, edit each mapping and find the User ID property. It is blank by default. Select the text input to the left, and in the Event Variables search bar, enter the text userId. Now you should see: