From c75366d22a25d1025fb7e29618ee29ab68df9913 Mon Sep 17 00:00:00 2001 From: Utsab Chowdhury Date: Tue, 28 May 2024 12:35:24 +0530 Subject: [PATCH] fix: add event name for custom mappings --- src/v0/destinations/ga4/customMappingsHandler.js | 10 ++++------ .../destinations/ga4/processor/customMappings.ts | 5 ++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/v0/destinations/ga4/customMappingsHandler.js b/src/v0/destinations/ga4/customMappingsHandler.js index 34da71d4aa..48ce92252f 100644 --- a/src/v0/destinations/ga4/customMappingsHandler.js +++ b/src/v0/destinations/ga4/customMappingsHandler.js @@ -74,8 +74,6 @@ const handleCustomMappings = (message, Config) => { const ga4EventPayload = {}; - ga4EventPayload.name = rsEvent; - // take optional params parameters for custom events ga4EventPayload.params = { ...ga4EventPayload.params, @@ -99,7 +97,7 @@ const handleCustomMappings = (message, Config) => { rawPayload = removeUndefinedAndNullValues(rawPayload); rawPayload = { ...rawPayload, events: [ga4EventPayload] }; - boilerplateOperations(rawPayload, message, Config); + boilerplateOperations(rawPayload, message, Config, rsEvent); return rawPayload; } @@ -125,7 +123,7 @@ const handleCustomMappings = (message, Config) => { } removeUndefinedAndNullRecurse(ga4MappedPayload); - boilerplateOperations(ga4MappedPayload, message, Config); + boilerplateOperations(ga4MappedPayload, message, Config, eventName); if (isDefinedAndNotNull(ga4BasicPayload)) { return { ...ga4BasicPayload, ...ga4MappedPayload }; @@ -139,9 +137,9 @@ const handleCustomMappings = (message, Config) => { ); }; -const boilerplateOperations = (ga4Payload, 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 && integrationsObj.sessionId) { diff --git a/test/integrations/destinations/ga4/processor/customMappings.ts b/test/integrations/destinations/ga4/processor/customMappings.ts index 8caafa3c30..e8186498b7 100644 --- a/test/integrations/destinations/ga4/processor/customMappings.ts +++ b/test/integrations/destinations/ga4/processor/customMappings.ts @@ -281,6 +281,7 @@ export const customMappingTestCases = [ client_id: 'root_anonId', events: [ { + name: 'view_item_list', params: { items: [ { @@ -380,6 +381,7 @@ export const customMappingTestCases = [ client_id: 'root_anonId', events: [ { + name: 'add_to_cart', params: { items: [ { @@ -442,6 +444,7 @@ export const customMappingTestCases = [ client_id: 'root_anonId', events: [ { + name: 'checkout_started', params: { items: [ { @@ -644,7 +647,7 @@ export const customMappingTestCases = [ timestamp_micros: 1651105389000000, non_personalized_ads: false, client_id: 'root_anonId', - events: [{}], + events: [{ name: 'join_group' }], userProperties: { firstName: { value: 'John',