Skip to content

Commit

Permalink
Updated utils getDestinationEventName() to return only array instead …
Browse files Browse the repository at this point in the history
…of two values
  • Loading branch information
Shivam4415 committed Dec 21, 2020
1 parent d912d0b commit 8f7eab6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
45 changes: 19 additions & 26 deletions integrations/GA4/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,23 @@ export default class GA4 {
handleEventMapper(eventMappingObj, properties, products) {
let destinationProperties = {};
const event = eventMappingObj.dest;
if (Array.isArray(eventMappingObj)) {
/* Recursion approach to send multiple payload to GA4 for single event from rudder payload
if (eventMappingObj.onlyIncludeParams) {
/* Only include params that are present in given mapping config for things like Cart/Product shared, Product/Products shared
*/
eventMappingObj.forEach((d) => {
// eslint-disable-next-line no-param-reassign
this.handleEventMapper(d, properties, products);
});
const includeParams = eventMappingObj.onlyIncludeParams;
destinationProperties = this.getIncludedParameters(
includeParams,
properties
);
} else {
if (eventMappingObj.onlyIncludeParams) {
/* Only include params that are present in given mapping config for things like Cart/Product shared, Product/Products shared
*/
const includeParams = eventMappingObj.onlyIncludeParams;
destinationProperties = this.getIncludedParameters(
includeParams,
properties
);
} else {
destinationProperties = this.getdestinationProperties(
properties,
eventMappingObj.hasItem,
products,
eventMappingObj.includeList
);
}
this.sendGAEvent(event, destinationProperties, true, eventMappingObj);
destinationProperties = this.getdestinationProperties(
properties,
eventMappingObj.hasItem,
products,
eventMappingObj.includeList
);
}
this.sendGAEvent(event, destinationProperties, true, eventMappingObj);
}

/**
Expand All @@ -165,9 +156,11 @@ export default class GA4 {
if (!event || isReservedName(event)) {
throw Error("Cannot call un-named/reserved named track event");
}
const eventMappingObj = getDestinationEventName(event);
if (eventMappingObj) {
this.handleEventMapper(eventMappingObj, properties, products);
const eventMappingArray = getDestinationEventName(event);
if (eventMappingArray) {
eventMappingArray.forEach((events) => {
this.handleEventMapper(events, properties, products);
});
} else {
this.sendGAEvent(event, properties, false);
}
Expand Down
5 changes: 2 additions & 3 deletions integrations/GA4/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ function isReservedName(name) {
}

/**
* map rudder event name to ga4 ecomm event name and return object
* map rudder event name to ga4 ecomm event name and return array
* @param {*} event
*/
function getDestinationEventName(event) {
const eventConfig = eventNamesConfigArray.filter((p) =>
return eventNamesConfigArray.filter((p) =>
p.src.includes(event.toLowerCase())
);
return eventConfig.length === 1 ? eventConfig[0] : eventConfig;
}

/**
Expand Down

0 comments on commit 8f7eab6

Please sign in to comment.