-
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.
Merge remote-tracking branch 'origin/develop' into chore.dedicate-prs…
…-ut-dt
- Loading branch information
Showing
26 changed files
with
2,913 additions
and
26 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
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
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
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,31 @@ | ||
const { getMappingConfig } = require('../../util'); | ||
|
||
const ENDPOINT = 'https://api.topsort.com/v2/events'; | ||
|
||
const ConfigCategory = { | ||
TRACK: { | ||
type: 'track', | ||
name: 'TopsortTrackConfig', | ||
}, | ||
PLACEMENT: { name: 'TopsortPlacementConfig' }, | ||
ITEM: { name: 'TopsortItemConfig' }, | ||
PURCHASE_ITEM: { name: 'TopSortPurchaseProductConfig' }, | ||
}; | ||
|
||
const ECOMM_EVENTS_WITH_PRODUCT_ARRAY = [ | ||
'Cart Viewed', | ||
'Checkout Started', | ||
'Order Updated', | ||
'Order Completed', | ||
'Order Refunded', | ||
'Order Cancelled', | ||
]; | ||
|
||
const mappingConfig = getMappingConfig(ConfigCategory, __dirname); | ||
|
||
module.exports = { | ||
mappingConfig, | ||
ConfigCategory, | ||
ENDPOINT, | ||
ECOMM_EVENTS_WITH_PRODUCT_ARRAY, | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/v0/destinations/topsort/data/TopSortPurchaseProductConfig.json
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,24 @@ | ||
[ | ||
{ | ||
"destKey": "productId", | ||
"sourceKeys": ["product_id", "properties.product_id"] | ||
}, | ||
{ | ||
"destKey": "unitPrice", | ||
"sourceKeys": ["price", "properties.price"], | ||
"metadata": { | ||
"type": "toNumber" | ||
} | ||
}, | ||
{ | ||
"destKey": "quantity", | ||
"sourceKeys": ["quantity", "properties.quantity"], | ||
"metadata": { | ||
"toInt": true | ||
} | ||
}, | ||
{ | ||
"destKey": "vendorId", | ||
"sourceKeys": "properties.vendorId" | ||
} | ||
] |
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,15 @@ | ||
[ | ||
{ | ||
"destKey": "position", | ||
"sourceKeys": ["properties.position", "position"], | ||
"metadata": { | ||
"toInt": true | ||
}, | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "productId", | ||
"sourceKeys": ["properties.product_id", "product_id"], | ||
"required": false | ||
} | ||
] |
36 changes: 36 additions & 0 deletions
36
src/v0/destinations/topsort/data/TopsortPlacementConfig.json
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,36 @@ | ||
[ | ||
{ | ||
"destKey": "path", | ||
"sourceKeys": "context.page.path", | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "searchQuery", | ||
"sourceKeys": "properties.query", | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "page", | ||
"sourceKeys": "properties.pageNumber", | ||
"metadata": { | ||
"toInt": true | ||
}, | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "pageSize", | ||
"sourceKeys": "properties.pageSize", | ||
"metadata": { | ||
"toInt": true | ||
}, | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "categoryIds", | ||
"sourceKeys": "properties.category_id", | ||
"required": false, | ||
"metadata": { | ||
"toArray": true | ||
} | ||
} | ||
] |
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,27 @@ | ||
[ | ||
{ | ||
"destKey": "occurredAt", | ||
"sourceKeys": ["timestamp", "originalTimestamp"], | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "opaqueUserId", | ||
"sourceKeys": "anonymousId", | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "resolvedBidId", | ||
"sourceKeys": "properties.resolvedBidId", | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "entity", | ||
"sourceKeys": "properties.entity", | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "additionalAttribution", | ||
"sourceKeys": "properties.additionalAttribution", | ||
"required": false | ||
} | ||
] |
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,95 @@ | ||
const { ConfigCategory, mappingConfig } = require('./config'); | ||
const { getItemPayloads, addFinalPayload } = require('./utils'); | ||
const { constructPayload, generateUUID } = require('../../util'); | ||
|
||
const processImpressionsAndClicksUtility = { | ||
// Create event data object | ||
createEventData(basePayload, placementPayload, itemPayload, event) { | ||
return { | ||
topsortPayload: { | ||
...basePayload, | ||
placement: { | ||
...placementPayload, | ||
...itemPayload, | ||
}, | ||
id: generateUUID(), | ||
}, | ||
event, | ||
}; | ||
}, | ||
|
||
// Process events with a product array | ||
processProductArray({ | ||
products, | ||
basePayload, | ||
placementPayload, | ||
topsortEventName, | ||
finalPayloads, | ||
}) { | ||
const itemPayloads = getItemPayloads(products, mappingConfig[ConfigCategory.ITEM.name]); | ||
itemPayloads.forEach((itemPayload) => { | ||
const eventData = this.createEventData( | ||
basePayload, | ||
placementPayload, | ||
itemPayload, | ||
topsortEventName, | ||
); | ||
addFinalPayload(eventData, finalPayloads); | ||
}); | ||
}, | ||
|
||
// Process events with a single product | ||
processSingleProduct({ | ||
basePayload, | ||
placementPayload, | ||
message, | ||
topsortEventName, | ||
finalPayloads, | ||
}) { | ||
const itemPayload = constructPayload(message, mappingConfig[ConfigCategory.ITEM.name]); | ||
const eventData = this.createEventData( | ||
basePayload, | ||
placementPayload, | ||
itemPayload, | ||
topsortEventName, | ||
); | ||
|
||
// Ensure messageId is used instead of generating a UUID for single product events | ||
eventData.topsortPayload.id = message.messageId; | ||
|
||
// Add final payload with appropriate ID and other headers | ||
addFinalPayload(eventData, finalPayloads); | ||
}, | ||
|
||
processImpressionsAndClicks({ | ||
isProductArrayAvailable, | ||
basePayload, | ||
topsortEventName, | ||
finalPayloads, | ||
products, | ||
message, | ||
placementPayload, | ||
}) { | ||
if (isProductArrayAvailable) { | ||
// If product array is available, process the event with multiple products | ||
this.processProductArray({ | ||
basePayload, | ||
topsortEventName, | ||
finalPayloads, | ||
products, | ||
placementPayload, | ||
}); | ||
} else { | ||
// Otherwise, process the event with a single product | ||
this.processSingleProduct({ | ||
basePayload, | ||
topsortEventName, | ||
finalPayloads, | ||
message, | ||
placementPayload, | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { processImpressionsAndClicksUtility }; |
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,56 @@ | ||
const { ConfigCategory, mappingConfig } = require('./config'); | ||
const { getItemPayloads, addFinalPayload } = require('./utils'); | ||
const { constructPayload, generateUUID } = require('../../util'); | ||
|
||
const processPurchaseEventUtility = { | ||
// Create event data object for purchase events | ||
createEventData(basePayload, items, event) { | ||
return { | ||
topsortPayload: { | ||
...basePayload, | ||
items, | ||
id: generateUUID(), | ||
}, | ||
event, | ||
}; | ||
}, | ||
|
||
// Function to process events with a product array for purchase events | ||
processProductArray(args) { | ||
const { products, basePayload, topsortEventName, finalPayloads } = args; | ||
const itemPayloads = getItemPayloads( | ||
products, | ||
mappingConfig[ConfigCategory.PURCHASE_ITEM.name], | ||
); | ||
const eventData = this.createEventData(basePayload, itemPayloads, topsortEventName); | ||
addFinalPayload(eventData, finalPayloads); | ||
}, | ||
|
||
// Function to process events with a single product for purchase events | ||
processSingleProduct(args) { | ||
const { basePayload, message, topsortEventName, finalPayloads } = args; | ||
const itemPayload = constructPayload(message, mappingConfig[ConfigCategory.PURCHASE_ITEM.name]); | ||
const eventData = this.createEventData(basePayload, [itemPayload], topsortEventName); | ||
|
||
// Ensure messageId is used instead of generating a UUID for single product events | ||
eventData.topsortPayload.id = message.messageId; | ||
|
||
// Add final payload with appropriate ID and other headers | ||
addFinalPayload(eventData, finalPayloads); | ||
}, | ||
|
||
// Function to process purchase events (either with a product array or single product) | ||
processPurchaseEvent(args) { | ||
if (args.isProductArrayAvailable) { | ||
// Process the event with multiple products (product array) | ||
this.processProductArray(args); | ||
} else { | ||
// Process the event with a single product | ||
this.processSingleProduct(args); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
processPurchaseEventUtility, | ||
}; |
Oops, something went wrong.