From cfbea6c615e3ef63e06c0098ccdb19c70572c22a Mon Sep 17 00:00:00 2001 From: Utsab Chowdhury Date: Wed, 31 Jul 2024 17:07:18 +0530 Subject: [PATCH] feat(integrations): feature for server side container url support ga4 --- .../src/integrations/GA4/browser.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/analytics-js-integrations/src/integrations/GA4/browser.js b/packages/analytics-js-integrations/src/integrations/GA4/browser.js index 42e2f87bc..2f69a225b 100644 --- a/packages/analytics-js-integrations/src/integrations/GA4/browser.js +++ b/packages/analytics-js-integrations/src/integrations/GA4/browser.js @@ -8,7 +8,12 @@ import { import { Cookie } from '@rudderstack/analytics-js-common/v1.1/utils/storage/cookie'; import Logger from '../../utils/logger'; import { eventsConfig } from './config'; -import { constructPayload, flattenJsonPayload, removeTrailingSlashes } from '../../utils/utils'; +import { + constructPayload, + flattenJsonPayload, + isDefinedAndNotNull, + removeTrailingSlashes, +} from '../../utils/utils'; import { shouldSendUserId, prepareParamsAndEventName, @@ -39,6 +44,7 @@ export default class GA4 { this.overrideClientAndSessionId = config.overrideClientAndSessionId || false; this.sdkBaseUrl = removeTrailingSlashes(config.sdkBaseUrl) || 'https://www.googletagmanager.com'; + this.serverContainerUrl = config.serverContainerUrl || null; this.isExtendedGa4_V2 = config.isExtendedGa4_V2 || false; ({ shouldApplyDeviceModeTransformation: this.shouldApplyDeviceModeTransformation, @@ -57,6 +63,10 @@ export default class GA4 { window.gtag('js', new Date()); const gtagParameterObject = {}; + if (isDefinedAndNotNull(this.serverContainerUrl)) { + gtagParameterObject.server_container_url = this.serverContainerUrl; + } + if (this.capturePageView === 'rs') { gtagParameterObject.send_page_view = false; } @@ -71,7 +81,7 @@ export default class GA4 { gtagParameterObject.cookie_prefix = 'rs'; gtagParameterObject.client_id = this.analytics.getAnonymousId(); gtagParameterObject.session_id = this.analytics.getSessionId(); - } else if(!this.isExtendedGa4_V2){ + } else if (!this.isExtendedGa4_V2) { // Cookie migration logic const clientCookie = this.cookie.get('rs_ga'); const defaultGA4Cookie = this.cookie.get('_ga'); @@ -271,5 +281,3 @@ export default class GA4 { }; } } - -