Skip to content

Commit 0a12b80

Browse files
Merge pull request #5041 from segmentio/bobbyatsegment-patch-13
Add Client ID snippet to Gtag code example
2 parents a2d5e53 + 8c3d141 commit 0a12b80

File tree

1 file changed

+8
-3
lines changed
  • src/connections/destinations/catalog/actions-google-analytics-4

1 file changed

+8
-3
lines changed

src/connections/destinations/catalog/actions-google-analytics-4/index.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ Besides Engagement Time in Milliseconds, you can also generate your own `session
9494

9595
If you choose to integrate with Google Analytics 4 client-side (either with Segment's Google Analytics 4 Web destination or outside of Segment) _and_ also use Segment's Google Analytics 4 Cloud destination to send events through the API, you will have all the reserved parameters and sessions tracking information available in Google Analytics 4 reports.
9696

97-
When using Gtag, [Google generates a `session_id` and `session_number` when a session begins](https://support.google.com/analytics/answer/9191807?hl=en){:target='_blank'}. The `session_id` and `session_number` generated on the client can be passed as Event Parameters to stitch events sent through the API with the same session that was collected client-side. For events to stitch properly, server-side events must arrive within a 48 hour window of when the client-side events arrive.
97+
When using Gtag, [Google generates a `session_id` and `session_number` when a session begins](https://support.google.com/analytics/answer/9191807?hl=en){:target='_blank'}. The `session_id` and `session_number` generated on the client can be passed as Event Parameters to stitch events sent through the API with the same session that was collected client-side. Additionally, `client_id` must be the same for both client-side and server-side events in order to deduplicate user counts in GA4 (unless User-ID is used as the basis for user identification). For events to stitch properly, server-side events must arrive within a 48 hour window of when the client-side events arrive.
9898

99-
You can check your `session_id` and `session_number` with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference){:target='_blank'} or by running this script in your JavaScript console and replacing `G-xxxxxxxxxx` with your Google Analytics 4 Measurement ID:
99+
You can check your `client_id`, `session_id` and `session_number` with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference){:target='_blank'} or by running this script in your JavaScript console and replacing `G-xxxxxxxxxx` with your Google Analytics 4 Measurement ID:
100100

101101
```java
102102
const sessionIdPromise = new Promise(resolve => {
@@ -106,9 +106,14 @@ const sessionNumPromise = new Promise(resolve => {
106106
gtag('get', 'G-xxxxxxxxxx', 'session_number', resolve)
107107
});
108108

109-
Promise.all([sessionIdPromise, sessionNumPromise]).then(function(session_data) {
109+
const clientIdPromise = new Promise(resolve => {
110+
gtag('get', 'G-xxxxxxxxxx', 'client_id', resolve)
111+
});
112+
113+
Promise.all([sessionIdPromise, sessionNumPromise, clientIdPromise]).then(function(session_data) {
110114
console.log("session ID: "+session_data[0]);
111115
console.log("session Number: "+session_data[1]);
116+
console.log("client ID: "+session_data[2]);
112117
});
113118
```
114119

0 commit comments

Comments
 (0)