Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: property and event name mappings in shopify v2 #3941

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion src/v1/sources/shopify/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,17 @@ const PIXEL_EVENT_MAPPING = {
checkout_address_info_submitted: 'Checkout Address Info Submitted',
checkout_contact_info_submitted: 'Checkout Contact Info Submitted',
checkout_shipping_info_submitted: 'Checkout Shipping Info Submitted',
payment_info_submitted: 'Payment Info Submitted',
payment_info_submitted: 'Payment Info Entered',
search_submitted: 'Search Submitted',
};

const RUDDER_ECOM_MAP = {
checkouts_create: 'Checkout Started Server',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checkout Started Webhook makes more sense ?

checkouts_update: 'Checkout Updated',
orders_updated: 'Order Updated',
orders_create: 'Order Created',
};

const contextualFieldMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'contextualFieldMapping.json')),
);
Expand Down Expand Up @@ -63,6 +70,14 @@ const checkoutStartedCompletedEventMappingJSON = JSON.parse(
),
);

const productMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'webhookEventsMapping', 'productMapping.json')),
);

const lineItemsMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'webhookEventsMapping', 'lineItemsMapping.json')),
);

const pixelEventToCartTokenLocationMapping = {
cart_viewed: 'properties.cart_id',
checkout_address_info_submitted: commonCartTokenLocation,
Expand All @@ -79,11 +94,14 @@ module.exports = {
INTEGERATION,
PIXEL_EVENT_TOPICS,
PIXEL_EVENT_MAPPING,
RUDDER_ECOM_MAP,
contextualFieldMappingJSON,
cartViewedEventMappingJSON,
productListViewedEventMappingJSON,
productViewedEventMappingJSON,
productToCartEventMappingJSON,
checkoutStartedCompletedEventMappingJSON,
pixelEventToCartTokenLocationMapping,
productMappingJSON,
lineItemsMappingJSON,
};
112 changes: 112 additions & 0 deletions src/v1/sources/shopify/webhookEventsMapping/identifyMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
[
{
"sourceKeys": "id",
"destKeys": "userId"
},
{
"sourceKeys": "email",
"destKeys": "traits.email"
},

{
"sourceKeys": "first_name",
"destKeys": "traits.firstName"
},

{
"sourceKeys": "last_name",
"destKeys": "traits.lastName"
},

{
"sourceKeys": "phone",
"destKeys": "traits.phone"
},

{
"sourceKeys": "addresses",
"destKeys": "traits.addressList"
},

{
"sourceKeys": "default_address",
"destKeys": "traits.address"
},

{
"sourceKeys": "shipping_address",
"destKeys": "traits.shippingAddress"
},

{
"sourceKeys": "billing_address",
"destKeys": "traits.billingAddress"
},

{
"sourceKeys": "accepts_marketing",
"destKeys": "traits.acceptsMarketing"
},

{
"sourceKeys": "orders_count",
"destKeys": "traits.orderCount"
},

{
"sourceKeys": "state",
"destKeys": "traits.state"
},
{
"sourceKeys": "total_spent",
"destKeys": "traits.totalSpent"
},
{
"sourceKeys": "note",
"destKeys": "traits.note"
},
{
"sourceKeys": "verified_email",
"destKeys": "traits.verifiedEmail"
},
{
"sourceKeys": "multipass_identifier",
"destKeys": "traits.multipassIdentifier"
},
{
"sourceKeys": "tax_exempt",
"destKeys": "traits.taxExempt"
},
{
"sourceKeys": "tags",
"destKeys": "traits.tags"
},
{
"sourceKeys": "last_order_name",
"destKeys": "traits.lastOrderName"
},
{
"sourceKeys": "currency",
"destKeys": "traits.currency"
},
{
"sourceKeys": "marketing_opt_in_level",
"destKeys": "traits.marketingOptInLevel"
},
{
"sourceKeys": "tax_exemptions",
"destKeys": "traits.taxExemptions"
},
{
"sourceKeys": "sms_marketing_consent",
"destKeys": "traits.smsMarketingConsent"
},
{
"sourceKeys": "admin_graphql_api_id",
"destKeys": "traits.adminGraphqlApiId"
},
{
"sourceKeys": "accepts_marketing_updated_at",
"destKeys": "traits.acceptsMarketingUpdatedAt"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"sourceKeys": "product_id",
"destKey": "product_id",
"metadata": {
"type": "toString"
}
},
{
"sourceKeys": "sku",
"destKey": "sku"
},
{
"sourceKeys": "name",
"destKey": "title"
},
{
"sourceKeys": "price",
"destKey": "price",
"metadata": {
"type": "toNumber"
}
},
{
"sourceKeys": "vendor",
"destKey": "brand"
},
{
"sourceKeys": "quantity",
"destKey": "quantity"
}
]
10 changes: 10 additions & 0 deletions src/v1/sources/shopify/webhookEventsMapping/mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"sourceKeys": "line_items",
"destKeys": "products"
},
{
"sourceKeys": "id",
"destKeys": "properties.order_id"
}
]
24 changes: 24 additions & 0 deletions src/v1/sources/shopify/webhookEventsMapping/productMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"sourceKeys": "id",
"destKey": "order_id",
"metadata": {
"type": "toString"
}
},
{
"sourceKeys": "total_price",
"destKey": "value"
},
{
"sourceKeys": "total_tax",
"destKey": "tax",
"metadata": {
"type": "toNumber"
}
},
{
"sourceKeys": "currency",
"destKey": "currency"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const {
MAPPING_CATEGORIES,
IDENTIFY_TOPICS,
ECOM_TOPICS,
RUDDER_ECOM_MAP,
SUPPORTED_TRACK_EVENTS,
SHOPIFY_TRACK_MAP,
lineItemsMappingJSON,
} = require('../../../../v0/sources/shopify/config');
const { RUDDER_ECOM_MAP } = require('../config');
const {
createPropertiesForEcomEventFromWebhook,
getProductsFromLineItems,
Expand Down Expand Up @@ -46,7 +46,7 @@ const ecomPayloadBuilder = (event, shopifyTopic) => {
message.setEventType(EventType.TRACK);
message.setEventName(RUDDER_ECOM_MAP[shopifyTopic]);

const properties = createPropertiesForEcomEventFromWebhook(event);
const properties = createPropertiesForEcomEventFromWebhook(event, shopifyTopic);
message.properties = removeUndefinedAndNullValues(properties);
// Map Customer details if present
const customerDetails = get(event, 'customer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ describe('serverSideUtils.js', () => {
const result = createPropertiesForEcomEventFromWebhook(message);
expect(result).toEqual({
products: [
{ brand: 'Hydrogen Vendor', price: '600.00', product_id: 7234590408818, quantity: 1 },
{ brand: 'Hydrogen Vendor', price: 600.0, product_id: '7234590408818', quantity: 1 },
{
brand: 'Hydrogen Vendor',
price: '600.00',
product_id: 7234590408817,
price: 600.0,
product_id: '7234590408817',
quantity: 1,
title: 'The Collection Snowboard: Nitrogen',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const { isDefinedAndNotNull } = require('@rudderstack/integrations-lib');
const { constructPayload } = require('../../../../v0/util');
const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we mapping any additional fields in the new flow or the old tracker flow is not inline with ecomm spec ?

lineItemsMappingJSON,
productMappingJSON,
} = require('../../../../v0/sources/shopify/config');
const { lineItemsMappingJSON, productMappingJSON } = require('../config');

/**
* Returns an array of products from the lineItems array received from the webhook event
Expand All @@ -28,12 +25,15 @@
* @param {Object} message
* @returns {Object} properties
*/
const createPropertiesForEcomEventFromWebhook = (message) => {
const createPropertiesForEcomEventFromWebhook = (message, shopifyTopic) => {
const { line_items: lineItems } = message;
if (!lineItems || lineItems.length === 0) {
return [];
}
const mappedPayload = constructPayload(message, productMappingJSON);
if (shopifyTopic === 'orders_updated' || shopifyTopic === 'checkouts_update') {
delete mappedPayload.value;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L35 was not covered by tests
}
mappedPayload.products = getProductsFromLineItems(lineItems, lineItemsMappingJSON);
return mappedPayload;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ export const pixelCheckoutStepsScenarios = [
SHOPIFY: true,
},
type: 'track',
event: 'Payment Info Submitted',
event: 'Payment Info Entered',
properties: {
buyerAcceptsEmailMarketing: false,
buyerAcceptsSmsMarketing: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ export const checkoutEventsTestScenarios = [
SHOPIFY: true,
},
type: 'track',
event: 'Checkout Started',
event: 'Checkout Started Server',
properties: {
order_id: 35550298931313,
order_id: '35550298931313',
value: '600.00',
tax: '0.00',
tax: 0,
currency: 'USD',
products: [
{
product_id: 7234590408817,
price: '600.00',
product_id: '7234590408817',
price: 600.0,
brand: 'Hydrogen Vendor',
quantity: 1,
},
Expand Down Expand Up @@ -533,17 +533,16 @@ export const checkoutEventsTestScenarios = [
},
properties: {
currency: 'USD',
order_id: 35374569160817,
order_id: '35374569160817',
products: [
{
brand: 'pixel-testing-rs',
price: '729.95',
product_id: 7234590638193,
price: 729.95,
product_id: '7234590638193',
quantity: 1,
},
],
tax: '0.00',
value: '736.85',
tax: 0,
},
timestamp: '2024-09-17T07:29:02.000Z',
traits: {
Expand Down Expand Up @@ -1207,15 +1206,14 @@ export const checkoutEventsTestScenarios = [
type: 'track',
event: 'Order Updated',
properties: {
order_id: 5778367414385,
value: '600.00',
tax: '0.00',
order_id: '5778367414385',
tax: 0,
currency: 'USD',
products: [
{
product_id: 7234590408817,
product_id: '7234590408817',
title: 'The Collection Snowboard: Hydrogen',
price: '600.00',
price: 600,
brand: 'Hydrogen Vendor',
quantity: 1,
},
Expand Down Expand Up @@ -1598,15 +1596,15 @@ export const checkoutEventsTestScenarios = [
type: 'track',
event: 'Order Created',
properties: {
order_id: 5778367414385,
order_id: '5778367414385',
value: '600.00',
tax: '0.00',
tax: 0,
currency: 'USD',
products: [
{
product_id: 7234590408817,
product_id: '7234590408817',
title: 'The Collection Snowboard: Hydrogen',
price: '600.00',
price: 600,
brand: 'Hydrogen Vendor',
quantity: 1,
},
Expand Down
Loading