Skip to content

Commit

Permalink
fix: stitched events through redis in pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Jan 7, 2025
1 parent 0c8251b commit 17cb53b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/v1/sources/shopify/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const RUDDER_ECOM_MAP = {
orders_create: 'Order Created',
};

const SERVERSIDE_STITCHED_EVENTS = Object.keys(RUDDER_ECOM_MAP);

const contextualFieldMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'contextualFieldMapping.json')),
);
Expand Down Expand Up @@ -95,6 +97,7 @@ module.exports = {
PIXEL_EVENT_TOPICS,
PIXEL_EVENT_MAPPING,
RUDDER_ECOM_MAP,
SERVERSIDE_STITCHED_EVENTS,
contextualFieldMappingJSON,
cartViewedEventMappingJSON,
productListViewedEventMappingJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
getProductsFromLineItems,
getAnonymousIdFromAttributes,
} = require('./serverSideUtlis');
const { getCartToken } = require('../../../../v0/sources/shopify/util');
const { getCartToken } = require('./serverSideUtlis');

const NO_OPERATION_SUCCESS = {
outputToSource: {
Expand Down
20 changes: 19 additions & 1 deletion src/v1/sources/shopify/webhookTransformations/serverSideUtlis.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { isDefinedAndNotNull } = require('@rudderstack/integrations-lib');
const { constructPayload } = require('../../../../v0/util');
const { lineItemsMappingJSON, productMappingJSON } = require('../config');
const {
lineItemsMappingJSON,
productMappingJSON,
SERVERSIDE_STITCHED_EVENTS,
} = require('../config');

/**
* Returns an array of products from the lineItems array received from the webhook event
Expand Down Expand Up @@ -54,8 +58,22 @@ const getAnonymousIdFromAttributes = (event) => {
return rudderAnonymousIdObject ? rudderAnonymousIdObject.value : null;
};

/**
* Returns the cart_token from the event message
* @param {Object} message
* @returns {String} cart_token
*/
const getCartToken = (message) => {
const { event, properties, context } = message;

Check warning on line 67 in src/v1/sources/shopify/webhookTransformations/serverSideUtlis.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/webhookTransformations/serverSideUtlis.js#L67

Added line #L67 was not covered by tests
if (SERVERSIDE_STITCHED_EVENTS.includes(event)) {
return context?.cart_token || properties?.cart_token || null;
}
return null;

Check warning on line 71 in src/v1/sources/shopify/webhookTransformations/serverSideUtlis.js

View check run for this annotation

Codecov / codecov/patch

src/v1/sources/shopify/webhookTransformations/serverSideUtlis.js#L71

Added line #L71 was not covered by tests
};

module.exports = {
createPropertiesForEcomEventFromWebhook,
getProductsFromLineItems,
getAnonymousIdFromAttributes,
getCartToken,
};

0 comments on commit 17cb53b

Please sign in to comment.