Skip to content

Commit

Permalink
Revert "Revert "Feature: Support Event Filtering for Device Mode Dest…
Browse files Browse the repository at this point in the history
…inations (#358)""

This reverts commit bbc1ace.
  • Loading branch information
saikumarrs committed Jan 25, 2022
1 parent c96b2ce commit c50ada6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ build.sh
publish.sh
dist/*
!dist/rudder-sdk-js/*
dist/rudder-sdk-js/index.js
coverage/**
__tests__/prodsdk.js
87 changes: 82 additions & 5 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
removeTrailingSlashes,
getConfigUrl,
checkSDKUrl,
commonNames,
} from "./utils/utils";
import {
MAX_WAIT_FOR_INTEGRATION_LOAD,
Expand Down Expand Up @@ -340,10 +341,18 @@ class Analytics {
if (
succesfulLoadedIntersectClientSuppliedIntegrations[i][methodName]
) {
const clonedBufferEvent = cloneDeep(event);
succesfulLoadedIntersectClientSuppliedIntegrations[i][methodName](
...clonedBufferEvent
const sendEvent = !object.IsEventBlackListed(
event[0].message.event,
succesfulLoadedIntersectClientSuppliedIntegrations[i].name
);

// Block the event if it is blacklisted for the device-mode destination
if (sendEvent) {
const clonedBufferEvent = cloneDeep(event);
succesfulLoadedIntersectClientSuppliedIntegrations[i][
methodName
](...clonedBufferEvent);
}
}
}
} catch (error) {
Expand Down Expand Up @@ -569,6 +578,66 @@ class Analytics {
);
}

IsEventBlackListed(eventName, intgName) {
if (!eventName || !(typeof eventName === "string")) {
return false;
}
const sdkIntgName = commonNames[intgName];
const intg = this.clientIntegrations.find(
(intg) => intg.name === sdkIntgName
);

const { blacklistedEvents, whitelistedEvents, eventFilteringOption } =
intg.config;

if (!eventFilteringOption) {
return false;
}

switch (eventFilteringOption) {
// disabled filtering
case "disable":
return false;
// Blacklist is choosen for filtering events
case "blacklistedEvents":
const isValidBlackList =
blacklistedEvents &&
Array.isArray(blacklistedEvents) &&
blacklistedEvents.every((x) => x.eventName !== "");

if (isValidBlackList) {
return blacklistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() ===
eventName.trim().toUpperCase()
) === undefined
? false
: true;
} else {
return false;
}
// Whitelist is choosen for filtering events
case "whitelistedEvents":
const isValidWhiteList =
whitelistedEvents &&
Array.isArray(whitelistedEvents) &&
whitelistedEvents.some((x) => x.eventName !== "");
if (isValidWhiteList) {
return whitelistedEvents.find(
(eventObj) =>
eventObj.eventName.trim().toUpperCase() ===
eventName.trim().toUpperCase()
) === undefined
? true
: false;
} else {
return true;
}
default:
return false;
}
}

/**
* Process and send data to destinations along with rudder BE
*
Expand Down Expand Up @@ -639,8 +708,16 @@ class Analytics {
succesfulLoadedIntersectClientSuppliedIntegrations.forEach((obj) => {
if (!obj.isFailed || !obj.isFailed()) {
if (obj[type]) {
const clonedRudderElement = cloneDeep(rudderElement);
obj[type](clonedRudderElement);
let sendEvent = !this.IsEventBlackListed(
rudderElement.message.event,
obj.name
);

// Block the event if it is blacklisted for the device-mode destination
if (sendEvent) {
const clonedRudderElement = cloneDeep(rudderElement);
obj[type](clonedRudderElement);
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ export {
isArray,
isDefinedAndNotNull,
getDataFromSource,
commonNames,
removeTrailingSlashes,
getConfigUrl,
checkSDKUrl,
Expand Down

0 comments on commit c50ada6

Please sign in to comment.