-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: onboard cordial source (#3593)
* feat: onboard cordial source * chore: test cases added * chore: minor fix * chore: changed v0 to v1 * chore: updated test case with batched payload * chore: updated test case * chore: removed cart object * chore: test cases updated and few minor fixes * chore: test cases updated for d and _id
- Loading branch information
Showing
4 changed files
with
707 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const eventsMapping = { | ||
crdl_app_install: 'Application Installed', | ||
crdl_app_open: 'Application Opened', | ||
}; | ||
|
||
module.exports = { eventsMapping }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"sourceKeys": "event._id", | ||
"destKeys": "properties.event_id" | ||
}, | ||
{ | ||
"sourceKeys": "contact._id", | ||
"destKeys": ["context.traits.userId", "userId"] | ||
}, | ||
{ | ||
"sourceKeys": ["event.ts", "event.ats"], | ||
"destKeys": ["timestamp", "sentAt", "originalTimestamp"] | ||
}, | ||
{ | ||
"sourceKeys": "event.d", | ||
"destKeys": "context.device" | ||
}, | ||
{ | ||
"sourceKeys": "contact.channels.email.address", | ||
"destKeys": ["context.traits.email"] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const Message = require('../../../v0/sources/message'); | ||
const { CommonUtils } = require('../../../util/common'); | ||
const { generateUUID, isDefinedAndNotNull } = require('../../../v0/util'); | ||
const { eventsMapping } = require('./config'); | ||
|
||
const mapping = require('./mapping.json'); | ||
|
||
const processEvent = (inputPaylaod) => { | ||
const message = new Message(`Cordial`); | ||
let eventName = inputPaylaod.event?.a || inputPaylaod.event?.action; | ||
if (eventName in eventsMapping) { | ||
eventName = eventsMapping[eventName]; | ||
} | ||
message.setEventType('track'); | ||
message.setEventName(eventName); | ||
message.setPropertiesV2(inputPaylaod, mapping); | ||
|
||
const externalId = []; | ||
// setting up cordial contact_id to externalId | ||
if (inputPaylaod.contact.cID) { | ||
externalId.push({ | ||
type: 'cordialContactId', | ||
id: inputPaylaod.contact.cID, | ||
}); | ||
} | ||
message.context.externalId = externalId; | ||
|
||
if (!isDefinedAndNotNull(message.userId)) { | ||
message.anonymousId = generateUUID(); | ||
} | ||
// Due to multiple mappings to the same destination path object some are not showing up due to which we are doing the following | ||
message.context.traits = { ...message.context.traits, ...inputPaylaod.contact }; | ||
message.properties = { | ||
...message.properties, | ||
...inputPaylaod.event.properties, | ||
...inputPaylaod.event, | ||
}; | ||
delete message.properties.properties; | ||
delete message.properties.d; | ||
// eslint-disable-next-line no-underscore-dangle | ||
delete message.properties._id; | ||
return message; | ||
}; | ||
|
||
const process = (inputEvent) => { | ||
const { event: events } = inputEvent; | ||
const eventsArray = CommonUtils.toArray(events); | ||
return eventsArray.map(processEvent); | ||
}; | ||
|
||
exports.process = process; |
Oops, something went wrong.