Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into chore.dedicate-prs…
Browse files Browse the repository at this point in the history
…-ut-dt
  • Loading branch information
Sai Sankeerth committed Dec 16, 2024
2 parents 2e53f2e + 227419f commit c42630c
Show file tree
Hide file tree
Showing 26 changed files with 2,913 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/cdk/v2/destinations/reddit/rtWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ steps:
description: Batches the successfulEvents using endpoint
condition: $.outputs.successfulEvents.length
template: |
let batches = $.batchEvents($.outputs.successfulEvents);
const dontBatchTrueEvents = $.outputs.successfulEvents{.metadata.dontBatch}[];
const dontBatchFalseEvents = $.outputs.successfulEvents{!.metadata.dontBatch}[];
const dontBatchTrueEventsChunks = $.chunk(dontBatchTrueEvents, 1);
let batches = [...$.batchEvents(dontBatchFalseEvents), ...$.batchEventChunks(dontBatchTrueEventsChunks)];
batches@batch.({
"batchedRequest": {
"body": {
Expand Down
1 change: 1 addition & 0 deletions src/cdk/v2/destinations/reddit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const populateRevenueField = (eventType, properties) => {
};
module.exports = {
batchEvents,
batchEventChunks,
populateRevenueField,
calculateDefaultRevenue,
};
1 change: 1 addition & 0 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const defaultFeaturesConfig: FeaturesConfig = {
AMAZON_AUDIENCE: true,
INTERCOM_V2: true,
LINKEDIN_AUDIENCE: true,
TOPSORT: true,
},
regulations: [
'BRAZE',
Expand Down
31 changes: 31 additions & 0 deletions src/v0/destinations/topsort/config.js
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 src/v0/destinations/topsort/data/TopSortPurchaseProductConfig.json
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"
}
]
15 changes: 15 additions & 0 deletions src/v0/destinations/topsort/data/TopsortItemConfig.json
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 src/v0/destinations/topsort/data/TopsortPlacementConfig.json
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
}
}
]
27 changes: 27 additions & 0 deletions src/v0/destinations/topsort/data/TopsortTrackConfig.json
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
}
]
95 changes: 95 additions & 0 deletions src/v0/destinations/topsort/impressions-and-clicks.js
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 };
56 changes: 56 additions & 0 deletions src/v0/destinations/topsort/purchase.js
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,
};
Loading

0 comments on commit c42630c

Please sign in to comment.