From 375c0a62513334a9028b0f9b19fcaf8dbc60ac23 Mon Sep 17 00:00:00 2001 From: Gavin-Fitzpatrick <89840737+Gavin-Fitzpatrick@users.noreply.github.com> Date: Thu, 19 May 2022 14:04:21 +0100 Subject: [PATCH 1/6] Session Id and Session Number using gtag --- .../catalog/actions-google-analytics-4/index.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index c84f759fac..741aff50cd 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -81,6 +81,20 @@ The Google Analytics 4 reports only display active users who engage with your si If you choose to integrate with Google Analytics 4 client-side (using Gtag outside of Segment) _and_ also use Segment's Google Analytics 4 destination to send events through the API, you can track sessions server-side. 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. +Ripping off that old section we could maybe add this line at the end of the Session section: +You can double-check your session_id and session_number with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference) or by running this script in your JavaScript console and replacing G-xxxxxxxxxx with your GA4 measurement ID: +```const sessionIdPromise = new Promise(resolve => { + gtag('get', 'G-xxxxxxxxxx', 'session_id', resolve) +}); +const sessionNumPromise = new Promise(resolve => { + gtag('get', 'G-xxxxxxxxxx', 'session_number', resolve) +}); + +Promise.all([sessionIdPromise, sessionNumPromise]).then(function(session_data) { + console.log("session ID: "+session_data[0]); + console.log("session Number: "+session_data[1]); +});``` + > info "Session tracking limitations" > Session tracking server-side only works if you're also sending data to Google Analytics 4 client-side. This is because the `session_id` must match a value that was previously collected on the client. For events to stitch properly, they must arrive within a 48 hour window of when the client-side events arrived. > From c818c91eef63394b4de25a6e4c4024c44b1979df Mon Sep 17 00:00:00 2001 From: Gavin-Fitzpatrick <89840737+Gavin-Fitzpatrick@users.noreply.github.com> Date: Thu, 19 May 2022 14:04:41 +0100 Subject: [PATCH 2/6] Update index.md --- .../destinations/catalog/actions-google-analytics-4/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index 741aff50cd..0d1a5ceb37 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -93,7 +93,8 @@ const sessionNumPromise = new Promise(resolve => { Promise.all([sessionIdPromise, sessionNumPromise]).then(function(session_data) { console.log("session ID: "+session_data[0]); console.log("session Number: "+session_data[1]); -});``` +}); +``` > info "Session tracking limitations" > Session tracking server-side only works if you're also sending data to Google Analytics 4 client-side. This is because the `session_id` must match a value that was previously collected on the client. For events to stitch properly, they must arrive within a 48 hour window of when the client-side events arrived. From 3bc0dc58f307ea60c7915b1abc6ee238d711a994 Mon Sep 17 00:00:00 2001 From: Gavin-Fitzpatrick <89840737+Gavin-Fitzpatrick@users.noreply.github.com> Date: Thu, 19 May 2022 14:05:41 +0100 Subject: [PATCH 3/6] Update index.md --- .../destinations/catalog/actions-google-analytics-4/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index 0d1a5ceb37..9689b3a235 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -81,7 +81,6 @@ The Google Analytics 4 reports only display active users who engage with your si If you choose to integrate with Google Analytics 4 client-side (using Gtag outside of Segment) _and_ also use Segment's Google Analytics 4 destination to send events through the API, you can track sessions server-side. 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. -Ripping off that old section we could maybe add this line at the end of the Session section: You can double-check your session_id and session_number with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference) or by running this script in your JavaScript console and replacing G-xxxxxxxxxx with your GA4 measurement ID: ```const sessionIdPromise = new Promise(resolve => { gtag('get', 'G-xxxxxxxxxx', 'session_id', resolve) From 846b6382e393c4190785ee1038521c1481faa736 Mon Sep 17 00:00:00 2001 From: Gavin-Fitzpatrick <89840737+Gavin-Fitzpatrick@users.noreply.github.com> Date: Thu, 19 May 2022 14:20:57 +0100 Subject: [PATCH 4/6] Update index.md --- .../destinations/catalog/actions-google-analytics-4/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index 9689b3a235..dcdaf0772e 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -82,7 +82,8 @@ The Google Analytics 4 reports only display active users who engage with your si If you choose to integrate with Google Analytics 4 client-side (using Gtag outside of Segment) _and_ also use Segment's Google Analytics 4 destination to send events through the API, you can track sessions server-side. 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. You can double-check your session_id and session_number with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference) or by running this script in your JavaScript console and replacing G-xxxxxxxxxx with your GA4 measurement ID: -```const sessionIdPromise = new Promise(resolve => { +``` +const sessionIdPromise = new Promise(resolve => { gtag('get', 'G-xxxxxxxxxx', 'session_id', resolve) }); const sessionNumPromise = new Promise(resolve => { From e2344d72f500330e3d446abeccd98cf68a338e5b Mon Sep 17 00:00:00 2001 From: stayseesong <83784848+stayseesong@users.noreply.github.com> Date: Thu, 19 May 2022 09:26:58 -0700 Subject: [PATCH 5/6] Apply suggestions from code review --- .../destinations/catalog/actions-google-analytics-4/index.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index dcdaf0772e..ca592c81bf 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -81,8 +81,8 @@ The Google Analytics 4 reports only display active users who engage with your si If you choose to integrate with Google Analytics 4 client-side (using Gtag outside of Segment) _and_ also use Segment's Google Analytics 4 destination to send events through the API, you can track sessions server-side. 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. -You can double-check your session_id and session_number with the [Google Site Tag function](https://developers.google.com/tag-platform/gtagjs/reference) or by running this script in your JavaScript console and replacing G-xxxxxxxxxx with your GA4 measurement ID: -``` +You can double-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 GA4 measurement ID: +```java const sessionIdPromise = new Promise(resolve => { gtag('get', 'G-xxxxxxxxxx', 'session_id', resolve) }); @@ -94,7 +94,6 @@ Promise.all([sessionIdPromise, sessionNumPromise]).then(function(session_data) { console.log("session ID: "+session_data[0]); console.log("session Number: "+session_data[1]); }); -``` > info "Session tracking limitations" > Session tracking server-side only works if you're also sending data to Google Analytics 4 client-side. This is because the `session_id` must match a value that was previously collected on the client. For events to stitch properly, they must arrive within a 48 hour window of when the client-side events arrived. From bd8dba1c238bc2a052cc69fa0a06b9aa1e4d98d4 Mon Sep 17 00:00:00 2001 From: stayseesong Date: Thu, 19 May 2022 09:31:25 -0700 Subject: [PATCH 6/6] fixes --- .../destinations/catalog/actions-google-analytics-4/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/connections/destinations/catalog/actions-google-analytics-4/index.md b/src/connections/destinations/catalog/actions-google-analytics-4/index.md index ca592c81bf..a6c89d88b9 100644 --- a/src/connections/destinations/catalog/actions-google-analytics-4/index.md +++ b/src/connections/destinations/catalog/actions-google-analytics-4/index.md @@ -82,6 +82,7 @@ The Google Analytics 4 reports only display active users who engage with your si If you choose to integrate with Google Analytics 4 client-side (using Gtag outside of Segment) _and_ also use Segment's Google Analytics 4 destination to send events through the API, you can track sessions server-side. 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. You can double-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 GA4 measurement ID: + ```java const sessionIdPromise = new Promise(resolve => { gtag('get', 'G-xxxxxxxxxx', 'session_id', resolve) @@ -94,6 +95,7 @@ Promise.all([sessionIdPromise, sessionNumPromise]).then(function(session_data) { console.log("session ID: "+session_data[0]); console.log("session Number: "+session_data[1]); }); +``` > info "Session tracking limitations" > Session tracking server-side only works if you're also sending data to Google Analytics 4 client-side. This is because the `session_id` must match a value that was previously collected on the client. For events to stitch properly, they must arrive within a 48 hour window of when the client-side events arrived.