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: update order_id in checkout events, messageId in pixel events #3794

Merged
merged 5 commits into from
Oct 21, 2024
Merged
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
8 changes: 7 additions & 1 deletion src/v1/sources/shopify/pixelTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const NO_OPERATION_SUCCESS = {

function processPixelEvent(inputEvent) {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { name, query_parameters, clientId, data } = inputEvent;
const { name, query_parameters, clientId, data, id } = inputEvent;
const shopifyDetails = { ...inputEvent };
delete shopifyDetails.context;
delete shopifyDetails.query_parameters;
delete shopifyDetails.pixelEventLabel;
const { checkout } = data ?? {};
const { order } = checkout ?? {};
const { customer } = order ?? {};
Expand Down Expand Up @@ -77,6 +81,8 @@ function processPixelEvent(inputEvent) {
version: '2.0.0',
});
message.setProperty('context.topic', name);
message.setProperty('context.shopifyDetails', shopifyDetails);
message.messageId = id;
message = removeUndefinedAndNullValues(message);
return message;
}
Expand Down
2 changes: 1 addition & 1 deletion src/v1/sources/shopify/pixelUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const checkoutEventBuilder = (inputEvent) => {

const properties = {
products,
order_id: inputEvent.id,
order_id: inputEvent.data?.checkout?.order?.id,
checkout_id: inputEvent?.data?.checkout?.token,
total: inputEvent?.data?.checkout?.totalPrice?.amount,
currency: inputEvent?.data?.checkout?.currencyCode,
Expand Down
3 changes: 3 additions & 0 deletions src/v1/sources/shopify/pixelUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ describe('utilV2.js', () => {
{ id: 'product123', name: 'Product 123' },
{ id: 'product456', name: 'Product 456' },
],
order: {
id: 'order123',
},
token: 'checkout123',
totalPrice: { amount: 200 },
currencyCode: 'USD',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,132 @@ export const pixelCheckoutEventsTestScenarios = [
version: '2.0.0',
},
topic: 'checkout_started',
shopifyDetails: {
clientId: 'c7b3f99b-4d34-463b-835f-c879482a7750',
data: {
checkout: {
attributes: [],
billingAddress: {
address1: null,
address2: null,
city: null,
country: 'US',
countryCode: 'US',
firstName: null,
lastName: null,
phone: null,
province: null,
provinceCode: null,
zip: null,
},
buyerAcceptsEmailMarketing: false,
buyerAcceptsSmsMarketing: false,
currencyCode: 'USD',
delivery: {
selectedDeliveryOptions: [],
},
discountApplications: [],
discountsAmount: {
amount: 0,
currencyCode: 'USD',
},
email: '',
lineItems: [
{
discountAllocations: [],
finalLinePrice: {
amount: 1499.9,
currencyCode: 'USD',
},
id: '41327143321713',
properties: [],
quantity: 2,
sellingPlanAllocation: null,
title: 'The Collection Snowboard: Liquid',
variant: {
id: '41327143321713',
image: {
src: 'https://cdn.shopify.com/s/files/1/0590/2696/4593/files/Main_b13ad453-477c-4ed1-9b43-81f3345adfd6_64x64.jpg?v=1724736600',
},
price: {
amount: 749.95,
currencyCode: 'USD',
},
product: {
id: '7234590834801',
title: 'The Collection Snowboard: Liquid',
type: 'snowboard',
untranslatedTitle: 'The Collection Snowboard: Liquid',
url: '/products/the-collection-snowboard-liquid',
vendor: 'Hydrogen Vendor',
},
sku: null,
title: null,
untranslatedTitle: null,
},
},
],
localization: {
country: {
isoCode: 'US',
},
language: {
isoCode: 'en-US',
},
market: {
handle: 'us',
id: 'gid://shopify/Market/23505895537',
},
},
order: {
customer: {
id: null,
isFirstOrder: null,
},
id: null,
},
phone: '',
shippingAddress: {
address1: null,
address2: null,
city: null,
country: 'US',
countryCode: 'US',
firstName: null,
lastName: null,
phone: null,
province: null,
provinceCode: null,
zip: null,
},
shippingLine: {
price: {
amount: 0,
currencyCode: 'USD',
},
},
smsMarketingPhone: null,
subtotalPrice: {
amount: 2759.8,
currencyCode: 'USD',
},
token: '5f7028e0bd5225c17b24bdaa0c09f914',
totalPrice: {
amount: 2759.8,
currencyCode: 'USD',
},
totalTax: {
amount: 0,
currencyCode: 'USD',
},
transactions: [],
},
},
id: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
name: 'checkout_started',
timestamp: '2024-09-15T20:57:59.674Z',
type: 'standard',
},
},
integrations: {
SHOPIFY: true,
Expand Down Expand Up @@ -238,7 +364,7 @@ export const pixelCheckoutEventsTestScenarios = [
brand: 'Hydrogen Vendor',
},
],
order_id: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
order_id: null,
checkout_id: '5f7028e0bd5225c17b24bdaa0c09f914',
total: 2759.8,
currency: 'USD',
Expand All @@ -249,6 +375,7 @@ export const pixelCheckoutEventsTestScenarios = [
tax: 0,
},
anonymousId: 'c7b3f99b-4d34-463b-835f-c879482a7750',
messageId: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
},
],
},
Expand Down Expand Up @@ -495,6 +622,165 @@ export const pixelCheckoutEventsTestScenarios = [
version: '2.0.0',
},
topic: 'checkout_completed',
shopifyDetails: {
clientId: 'c7b3f99b-4d34-463b-835f-c879482a7750',
data: {
checkout: {
attributes: [],
billingAddress: {
address1: null,
address2: null,
city: null,
country: 'US',
countryCode: 'US',
firstName: null,
lastName: null,
phone: null,
province: null,
provinceCode: null,
zip: null,
},
buyerAcceptsEmailMarketing: false,
buyerAcceptsSmsMarketing: false,
currencyCode: 'USD',
delivery: {
selectedDeliveryOptions: [],
},
discountApplications: [],
discountsAmount: {
amount: 0,
currencyCode: 'USD',
},
email: '',
lineItems: [
{
discountAllocations: [],
finalLinePrice: {
amount: 1499.9,
currencyCode: 'USD',
},
id: '41327143321713',
properties: [],
quantity: 2,
sellingPlanAllocation: null,
title: 'The Collection Snowboard: Liquid',
variant: {
id: '41327143321713',
image: {
src: 'https://cdn.shopify.com/s/files/1/0590/2696/4593/files/Main_b13ad453-477c-4ed1-9b43-81f3345adfd6_64x64.jpg?v=1724736600',
},
price: {
amount: 749.95,
currencyCode: 'USD',
},
product: {
id: '7234590834801',
title: 'The Collection Snowboard: Liquid',
type: 'snowboard',
untranslatedTitle: 'The Collection Snowboard: Liquid',
url: '/products/the-collection-snowboard-liquid',
vendor: 'Hydrogen Vendor',
},
sku: null,
title: null,
untranslatedTitle: null,
},
},
{
discountAllocations: [],
finalLinePrice: {
amount: 1259.9,
currencyCode: 'USD',
},
id: '41327143157873',
properties: [],
quantity: 2,
sellingPlanAllocation: null,
title: 'The Multi-managed Snowboard',
variant: {
id: '41327143157873',
image: {
src: 'https://cdn.shopify.com/s/files/1/0590/2696/4593/files/Main_9129b69a-0c7b-4f66-b6cf-c4222f18028a_64x64.jpg?v=1724736597',
},
price: {
amount: 629.95,
currencyCode: 'USD',
},
product: {
id: '7234590736497',
title: 'The Multi-managed Snowboard',
type: 'snowboard',
untranslatedTitle: 'The Multi-managed Snowboard',
url: '/products/the-multi-managed-snowboard',
vendor: 'Multi-managed Vendor',
},
sku: 'sku-managed-1',
title: null,
untranslatedTitle: null,
},
},
],
localization: {
country: {
isoCode: 'US',
},
language: {
isoCode: 'en-US',
},
market: {
handle: 'us',
id: 'gid://shopify/Market/23505895537',
},
},
order: {
customer: {
id: null,
isFirstOrder: null,
},
id: null,
},
phone: '',
shippingAddress: {
address1: null,
address2: null,
city: null,
country: 'US',
countryCode: 'US',
firstName: null,
lastName: null,
phone: null,
province: null,
provinceCode: null,
zip: null,
},
shippingLine: {
price: {
amount: 0,
currencyCode: 'USD',
},
},
smsMarketingPhone: null,
subtotalPrice: {
amount: 2759.8,
currencyCode: 'USD',
},
token: '5f7028e0bd5225c17b24bdaa0c09f914',
totalPrice: {
amount: 2759.8,
currencyCode: 'USD',
},
totalTax: {
amount: 0,
currencyCode: 'USD',
},
transactions: [],
},
},
id: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
name: 'checkout_completed',
timestamp: '2024-09-15T20:57:59.674Z',
type: 'standard',
},
},
integrations: {
SHOPIFY: true,
Expand Down Expand Up @@ -548,7 +834,7 @@ export const pixelCheckoutEventsTestScenarios = [
brand: 'Multi-managed Vendor',
},
],
order_id: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
order_id: null,
checkout_id: '5f7028e0bd5225c17b24bdaa0c09f914',
total: 2759.8,
currency: 'USD',
Expand All @@ -559,6 +845,7 @@ export const pixelCheckoutEventsTestScenarios = [
tax: 0,
},
anonymousId: 'c7b3f99b-4d34-463b-835f-c879482a7750',
messageId: 'sh-f77a78f1-C1D8-4ED4-9C9B-0D352CF6F3BF',
},
],
},
Expand Down
Loading
Loading