Skip to content

Commit

Permalink
chore(release): pull main into develop post release v1.72.4 (#3610)
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc authored Jul 26, 2024
2 parents cdea69c + b0fc288 commit b9056d7
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.72.4](https://github.com/rudderlabs/rudder-transformer/compare/v1.72.3...v1.72.4) (2024-07-25)


### Bug Fixes

* added support for ga4 v2 hybrid mode ([#3586](https://github.com/rudderlabs/rudder-transformer/issues/3586)) ([dedca07](https://github.com/rudderlabs/rudder-transformer/commit/dedca0796ee12478d57e020ef3c254afabc6e105))

### [1.72.3](https://github.com/rudderlabs/rudder-transformer/compare/v1.72.2...v1.72.3) (2024-07-24)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rudder-transformer",
"version": "1.72.3",
"version": "1.72.4",
"description": "",
"homepage": "https://github.com/rudderlabs/rudder-transformer#readme",
"bugs": {
Expand Down
8 changes: 8 additions & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ const DestCanonicalNames = {
awin: ['awin', 'Awin', 'AWIN'],
sendinblue: ['sendinblue', 'SENDINBLUE', 'Sendinblue', 'SendinBlue'],
ga4: ['GA4', 'ga4', 'Ga4', 'Google Analytics 4', 'googleAnalytics4', 'Google Analytics 4 (GA4)'],
ga4_v2: [
'GA4_V2',
'ga4_v2',
'Ga4_v2',
'Google Analytics 4 V2',
'googleAnalytics4V2',
'Google Analytics 4 (GA4) V2',
],
pipedream: ['Pipedream', 'PipeDream', 'pipedream', 'PIPEDREAM'],
pagerduty: ['pagerduty', 'PAGERDUTY', 'PagerDuty', 'Pagerduty', 'pagerDuty'],
adobe_analytics: [
Expand Down
21 changes: 12 additions & 9 deletions src/v0/destinations/ga4/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require('../../util/constant');
* @param {*} Config
* @returns
*/
const responseBuilder = (message, { Config }) => {
const responseBuilder = (message, { Config }, destType) => {
let event = get(message, 'event');
basicValidation(event);

Expand All @@ -54,7 +54,7 @@ const responseBuilder = (message, { Config }) => {
// get common top level rawPayload
let rawPayload = constructPayload(message, trackCommonConfig);

rawPayload = addClientDetails(rawPayload, message, Config);
rawPayload = addClientDetails(rawPayload, message, Config, destType);

let payload = {};
const eventConfig = ConfigCategory[`${event.toUpperCase()}`];
Expand Down Expand Up @@ -162,7 +162,7 @@ const responseBuilder = (message, { Config }) => {
}

removeReservedParameterPrefixNames(payload.params);
const integrationsObj = getIntegrationsObj(message, 'ga4');
const integrationsObj = getIntegrationsObj(message, destType);
if (isHybridModeEnabled(Config) && integrationsObj && integrationsObj.sessionId) {
payload.params.session_id = integrationsObj.sessionId;
}
Expand All @@ -186,7 +186,7 @@ const responseBuilder = (message, { Config }) => {
}

// Prepare GA4 consents
const consents = prepareUserConsents(message);
const consents = prepareUserConsents(message, destType);
if (!isEmptyObject(consents)) {
rawPayload.consent = consents;
}
Expand All @@ -197,7 +197,7 @@ const responseBuilder = (message, { Config }) => {
return buildDeliverablePayload(rawPayload, Config);
};

const process = (event) => {
const processEvents = ({ event, destType = 'ga4' }) => {
const { message, destination } = event;
const { Config } = destination;

Expand All @@ -212,13 +212,13 @@ const process = (event) => {
let response;
switch (messageType) {
case EventType.TRACK:
response = responseBuilder(message, destination);
response = responseBuilder(message, destination, destType);
break;
case EventType.PAGE:
// GA4 custom event 'page_view' is fired for page
if (!isHybridModeEnabled(Config)) {
message.event = 'page_view';
response = responseBuilder(message, destination);
response = responseBuilder(message, destination, destType);
} else {
throw new UnsupportedEventError(
'GA4 Hybrid mode is enabled, page calls will be sent through device mode',
Expand All @@ -228,12 +228,15 @@ const process = (event) => {
case EventType.GROUP:
// GA4 standard event 'join_group' is fired for group
message.event = 'join_group';
response = responseBuilder(message, destination);
response = responseBuilder(message, destination, destType);
break;
default:
throw new InstrumentationError(`Message type ${messageType} not supported`);
}
return response;
};

module.exports = { process };
// Keeping this for other params which comes as part of process args
const process = (event) => processEvents({ event });

module.exports = { process, processEvents };
23 changes: 17 additions & 6 deletions src/v0/destinations/ga4/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ const prepareUserProperties = (message, piiPropertiesToIgnore = []) => {
* @param {*} message
* @returns
*/
const prepareUserConsents = (message) => {
const integrationObj = getIntegrationsObj(message, 'ga4') || {};
const prepareUserConsents = (message, destType = 'ga4') => {
const integrationObj = getIntegrationsObj(message, destType) || {};
const eventLevelConsentsData = integrationObj?.consents || {};
const consentConfigMap = {
analyticsPersonalizationConsent: 'ad_user_data',
Expand All @@ -474,11 +474,11 @@ const basicValidation = (event) => {
* @param {*} message
* @returns
*/
const getGA4ClientId = (message, Config) => {
const getGA4ClientId = (message, Config, destType) => {
let clientId;

if (isHybridModeEnabled(Config)) {
const integrationsObj = getIntegrationsObj(message, 'ga4');
const integrationsObj = getIntegrationsObj(message, destType);
if (integrationsObj?.clientId) {
clientId = integrationsObj.clientId;
}
Expand All @@ -494,14 +494,14 @@ const getGA4ClientId = (message, Config) => {
return clientId;
};

const addClientDetails = (payload, message, Config) => {
const addClientDetails = (payload, message, Config, destType = 'ga4') => {
const { typesOfClient } = Config;
const rawPayload = cloneDeep(payload);
switch (typesOfClient) {
case 'gtag':
// gtag.js uses client_id
// GA4 uses it as an identifier to distinguish site visitors.
rawPayload.client_id = getGA4ClientId(message, Config);
rawPayload.client_id = getGA4ClientId(message, Config, destType);
if (!isDefinedAndNotNull(rawPayload.client_id)) {
throw new ConfigurationError('ga4ClientId, anonymousId or messageId must be provided');
}
Expand Down Expand Up @@ -581,6 +581,16 @@ const basicConfigvalidaiton = (Config) => {
}
};

const addSessionDetailsForHybridMode = (ga4Payload, message, Config, destType = 'ga4') => {
const integrationsObj = getIntegrationsObj(message, destType);
if (isHybridModeEnabled(Config) && integrationsObj?.sessionId) {
ga4Payload.events[0].params.session_id = `${integrationsObj.sessionId}`;
}
if (integrationsObj?.sessionNumber) {
ga4Payload.events[0].params.session_number = integrationsObj.sessionNumber;
}
};

module.exports = {
addClientDetails,
basicValidation,
Expand All @@ -603,4 +613,5 @@ module.exports = {
GA4_RESERVED_PARAMETER_EXCLUSION,
removeReservedParameterPrefixNames,
GA4_RESERVED_USER_PROPERTY_EXCLUSION,
addSessionDetailsForHybridMode,
};
14 changes: 7 additions & 7 deletions src/v0/destinations/ga4_v2/customMappingsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
GA4_PARAMETERS_EXCLUSION,
prepareUserProperties,
sanitizeUserProperties,
addSessionDetailsForHybridMode,
} = require('../ga4/utils');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const {
Expand Down Expand Up @@ -71,6 +72,7 @@ const handleCustomMappings = (message, Config) => {
// Default mapping

let rawPayload = constructPayload(message, trackCommonConfig);
rawPayload = addClientDetails(rawPayload, message, Config, 'ga4_v2');

const ga4EventPayload = {};

Expand Down Expand Up @@ -113,7 +115,7 @@ const handleCustomMappings = (message, Config) => {

// Add common top level payload
let ga4BasicPayload = constructPayload(message, trackCommonConfig);
ga4BasicPayload = addClientDetails(ga4BasicPayload, message, Config);
ga4BasicPayload = addClientDetails(ga4BasicPayload, message, Config, 'ga4_v2');

const eventPropertiesMappings = mapping.eventProperties || [];

Expand Down Expand Up @@ -143,11 +145,7 @@ const handleCustomMappings = (message, Config) => {
const boilerplateOperations = (ga4Payload, message, Config, eventName) => {
removeReservedParameterPrefixNames(ga4Payload.events[0].params);
ga4Payload.events[0].name = eventName;
const integrationsObj = getIntegrationsObj(message, 'ga4');

if (isHybridModeEnabled(Config) && integrationsObj?.sessionId) {
ga4Payload.events[0].params.session_id = integrationsObj.sessionId;
}
const integrationsObj = getIntegrationsObj(message, 'ga4_v2');

if (ga4Payload.events[0].params) {
ga4Payload.events[0].params = removeInvalidParams(
Expand All @@ -160,7 +158,7 @@ const boilerplateOperations = (ga4Payload, message, Config, eventName) => {
}

// Prepare GA4 consents
const consents = prepareUserConsents(message);
const consents = prepareUserConsents(message, 'ga4_v2');
if (!isEmptyObject(consents)) {
ga4Payload.consent = consents;
}
Expand All @@ -169,6 +167,8 @@ const boilerplateOperations = (ga4Payload, message, Config, eventName) => {
if (isDefinedAndNotNull(ga4Payload.user_properties)) {
ga4Payload.user_properties = sanitizeUserProperties(ga4Payload.user_properties);
}

addSessionDetailsForHybridMode(ga4Payload, message, Config, 'ga4_v2');
};

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions src/v0/destinations/ga4_v2/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@rudderstack/integrations-lib';
import { ProcessorTransformationRequest } from '../../../types';
import { handleCustomMappings } from './customMappingsHandler';
import { process as ga4Process } from '../ga4/transform';
import { processEvents as ga4Process } from '../ga4/transform';
import { basicConfigvalidaiton } from '../ga4/utils';

export function process(event: ProcessorTransformationRequest) {
Expand All @@ -30,7 +30,7 @@ export function process(event: ProcessorTransformationRequest) {
}

if (eventPayload.type !== 'track') {
return ga4Process(event);
return ga4Process({ event, destType: 'ga4_v2' });
}

basicConfigvalidaiton(Config);
Expand Down
Loading

0 comments on commit b9056d7

Please sign in to comment.