Skip to content

Commit

Permalink
feat(integrations): feature for server side container url support ga4 (
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc authored Aug 1, 2024
2 parents 2d65fe1 + cfbea6c commit 2e54ec0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/analytics-js-integrations/src/integrations/GA4/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
Expand All @@ -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');
Expand Down Expand Up @@ -271,5 +281,3 @@ export default class GA4 {
};
}
}


0 comments on commit 2e54ec0

Please sign in to comment.