Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/util/oncehub-custom-transformer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const { EventType } = require('../constants');

const getBlockedEventsByDestination = () => {
try {
return JSON.parse(process.env.BLOCKED_EVENTS_DESTINATIONS || '{}');
} catch (error) {
console.error('Error parsing BLOCKED_EVENTS_DESTINATIONS:', error);

Check warning on line 7 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Unexpected console statement

Check warning on line 7 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Unexpected console statement
return {};
}
};

const getPIIDestinationList = () => {
return (process.env.WHITELIST_PII_DESTINATION || 'customerio').trim().split(',');
};
Expand All @@ -11,14 +20,14 @@
const doesEventContainContextTraits = (event) => {
return event && event.message && event.message.context && event.message.context.traits;
};

Check failure on line 23 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Assignment to property of function parameter 'traits'

Check failure on line 23 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Assignment to property of function parameter 'traits'
const getPageEventBlockedDestinationsList = () => {
return (process.env.BLOCKED_PAGE_DESTINATIONS || '').trim().split(',');
};

const handleFirstLoginGA4Property = (destination, event, traits) => {
// delete firstLoginGA4 property from traits when destination is not GA4

Check failure on line 29 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Assignment to property of function parameter 'traits'

Check failure on line 29 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Assignment to property of function parameter 'traits'
if (destination !== 'ga4') {

Check failure on line 30 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Assignment to property of function parameter 'traits'

Check failure on line 30 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Assignment to property of function parameter 'traits'
delete traits.firstLoginGA4;
return;
}
Expand All @@ -45,7 +54,7 @@
}
if (eventTraitsPresent) {
// eslint-disable-next-line no-param-reassign
event.message.traits.accountCreatedDate = Math.floor(

Check failure on line 57 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Assignment to function parameter 'destination'

Check failure on line 57 in src/util/oncehub-custom-transformer.js

View workflow job for this annotation

GitHub Actions / Code Coverage

Assignment to function parameter 'destination'
Date.parse(event.message.traits.accountCreatedDate) / 1000,
);
}
Expand All @@ -63,6 +72,15 @@
// eslint-disable-next-line no-param-reassign
return null;
}
// Check if event should be blocked based on location-wise blacklist
const blacklist = getBlockedEventsByDestination();
if (
event.message.type === EventType.TRACK &&
blacklist[destination]?.includes(event.message.event)
) {
// eslint-disable-next-line no-param-reassign
return null;
}

changeDateFormatForCustomerio(
contextTraitsPresent,
Expand Down Expand Up @@ -100,7 +118,6 @@

// eslint-disable-next-line no-console
// if(doesEventContainsTraits(event)) console.log("event log=>destination : ", JSON.stringify(destination), " , ==> event traits : ", JSON.stringify(event.message.traits), " , ==> event here : ",JSON.stringify(event));

return event;
};

Expand Down
Loading