Skip to content

Commit

Permalink
feat: onboard shopify to v1 (#3665)
Browse files Browse the repository at this point in the history
* feat: onboard shopify to v1, initial commit

* chore: refactor, add pixel transformation definitions

* feat: add support for all pixel events in v1 shopify source

* fix: add customer id check

* chore: fix checks

* fix: add configs for new webhook topics and events from pixel app

* chore: update webhook event topic in mapping

* chore: refactor

* chore: update cart viewed logic

* chore: refactor pixel code logic and tests

* fix: library version for old and new serverside events

* chore: address comments, refactorx1

* chore: add test

* chore: add testsx2

* chore: update version naming from config

* chore: keep old v0 logic intact, refactor

* chore: sonarcloud reliability check fix

* chore: update util file names

* chore: move webhook specific logic for v2 pixel, address comments

* chore: more refactoring, update userId and anonymousid from customer object

* chore: update library name for pixel and webhook events in pixel app flow

* chore: refactor pixel tests to seperate directory, remove reduntant test data

---------

Co-authored-by: Krishna Chaitanya <[email protected]>
  • Loading branch information
yashasvibajpai and krishna2020 authored Sep 24, 2024
1 parent ede31ef commit d40e772
Show file tree
Hide file tree
Showing 20 changed files with 4,771 additions and 2 deletions.
52 changes: 52 additions & 0 deletions src/v0/sources/shopify/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ const SHOPIFY_TRACK_MAP = {
orders_fulfilled: 'Order Fulfilled',
orders_paid: 'Order Paid',
orders_partially_fullfilled: 'Order Partially Fulfilled',
// following are the events that supported by rudderstack pixel app as generic track events
customer_tags_added: 'Customer Tags Added',
customer_tags_removed: 'Customer Tags Removed',
customer_email_updated: 'Customer Email Updated',
collections_create: 'Collection Created',
collections_update: 'Collection Updated',
collections_delete: 'Collection Deleted',
collection_listings_add: 'Collection Listings Added',
collection_listings_remove: 'Collection Listings Removed',
collection_listings_update: 'Collection Listings Updated',
collection_publications_create: 'Collection Publications Created',
collection_publications_delete: 'Collection Publications Deleted',
collection_publications_update: 'Collection Publications Updated',
discounts_create: 'Discount Created',
discounts_delete: 'Discount Deleted',
discounts_update: 'Discount Updated',
draft_orders_create: 'Draft Order Created',
draft_orders_delete: 'Draft Order Deleted',
draft_orders_update: 'Draft Order Updated',
fulfillment_order_split: 'Fulfillment Order Split',
inventory_items_create: 'Inventory Items Created',
inventory_items_delete: 'Inventory Items Deleted',
inventory_items_update: 'Inventory Items Updated',
inventory_levels_connect: 'Inventory Levels Connected',
inventory_levels_disconnect: 'Inventory Levels Disconnected',
inventory_levels_update: 'Inventory Levels Updated',
};

const identifyMappingJSON = JSON.parse(
Expand Down Expand Up @@ -100,6 +126,32 @@ const SUPPORTED_TRACK_EVENTS = [
'orders_fulfilled',
'orders_paid',
'orders_partially_fullfilled',
// following are the events that supported by rudderstack pixel app as generic track events
'customer_tags_added',
'customer_tags_removed',
'customer_email_updated',
'collections_create',
'collections_update',
'collections_delete',
'collection_listings_add',
'collection_listings_remove',
'collection_listings_update',
'collection_publications_create',
'collection_publications_delete',
'collection_publications_update',
'discounts_create',
'discounts_delete',
'discounts_update',
'draft_orders_create',
'draft_orders_delete',
'draft_orders_update',
'fulfillment_order_split',
'inventory_items_create',
'inventory_items_delete',
'inventory_items_update',
'inventory_levels_connect',
'inventory_levels_disconnect',
'inventory_levels_update',
];

const maxTimeToIdentifyRSGeneratedCall = 10000; // in ms
Expand Down
8 changes: 7 additions & 1 deletion src/v0/sources/shopify/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,10 @@ const process = async (event) => {
return response;
};

exports.process = process;
module.exports = {
process,
processEvent,
identifyPayloadBuilder,
ecomPayloadBuilder,
trackPayloadBuilder,
};
76 changes: 76 additions & 0 deletions src/v1/sources/shopify/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const path = require('path');
const fs = require('fs');

const PIXEL_EVENT_TOPICS = {
CART_VIEWED: 'cart_viewed',
PRODUCT_ADDED_TO_CART: 'product_added_to_cart',
PRODUCT_REMOVED_FROM_CART: 'product_removed_from_cart',
PAGE_VIEWED: 'page_viewed',
PRODUCT_VIEWED: 'product_viewed',
COLLECTION_VIEWED: 'collection_viewed',
CHECKOUT_STARTED: 'checkout_started',
CHECKOUT_COMPLETED: 'checkout_completed',
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',
SEARCH_SUBMITTED: 'search_submitted',
};

const PIXEL_EVENT_MAPPING = {
cart_viewed: 'Cart Viewed',
product_added_to_cart: 'Product Added',
product_removed_from_cart: 'Product Removed',
page_viewed: 'Page Viewed',
product_viewed: 'Product Viewed',
collection_viewed: 'Collection Viewed',
checkout_started: 'Checkout Started',
checkout_completed: 'Checkout Completed',
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',
search_submitted: 'Search Submitted',
};

const contextualFieldMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'contextualFieldMapping.json')),
);

const cartViewedEventMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'cartViewedEventMapping.json')),
);

const productListViewedEventMappingJSON = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, 'pixelEventsMappings', 'productListViewedEventMapping.json'),
),
);

const productViewedEventMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'productViewedEventMapping.json')),
);

const productToCartEventMappingJSON = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'pixelEventsMappings', 'productToCartEventMapping.json')),
);

const checkoutStartedCompletedEventMappingJSON = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, 'pixelEventsMappings', 'checkoutStartedCompletedEventMapping.json'),
),
);

const INTEGERATION = 'SHOPIFY';

module.exports = {
INTEGERATION,
PIXEL_EVENT_TOPICS,
PIXEL_EVENT_MAPPING,
contextualFieldMappingJSON,
cartViewedEventMappingJSON,
productListViewedEventMappingJSON,
productViewedEventMappingJSON,
productToCartEventMappingJSON,
checkoutStartedCompletedEventMappingJSON,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"sourceKeys": "merchandise.product.id",
"destKeys": "product_id"
},
{
"sourceKeys": "merchandise.product.title",
"destKeys": "variant"
},
{
"sourceKeys": "merchandise.image.src",
"destKeys": "image_url"
},
{
"sourceKeys": "merchandise.price.amount",
"destKeys": "price"
},
{
"sourceKeys": "merchandise.product.type",
"destKeys": "category"
},
{
"sourceKeys": "merchandise.product.url",
"destKeys": "url"
},
{
"sourceKeys": "merchandise.product.vendor",
"destKeys": "brand"
},
{
"sourceKeys": "merchandise.sku",
"destKeys": "sku"
},
{
"sourceKeys": "merchandise.title",
"destKeys": "name"
},
{
"sourceKeys": "quantity",
"destKeys": "quantity"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"sourceKeys": "quantity",
"destKeys": "quantity"
},
{
"sourceKeys": "title",
"destKeys": "name"
},
{
"sourceKeys": "variant.image.src",
"destKeys": "image_url"
},
{
"sourceKeys": "variant.price.amount",
"destKeys": "price"
},
{
"sourceKeys": "variant.sku",
"destKeys": "sku"
},
{
"sourceKeys": "variant.product.id",
"destKeys": "product_id"
},
{
"sourceKeys": "variant.product.title",
"destKeys": "variant"
},
{
"sourceKeys": "variant.product.type",
"destKeys": "category"
},
{
"sourceKeys": "variant.product.url",
"destKeys": "url"
},
{
"sourceKeys": "variant.product.vendor",
"destKeys": "brand"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"sourceKeys": "context.document.referrer",
"destKeys": "page.referrer"
},
{
"sourceKeys": "document.title",
"destKeys": "page.title"
},
{
"sourceKeys": "navigator.userAgent",
"destKeys": "userAgent"
},
{
"sourceKeys": "window.location.href",
"destKeys": "page.url"
},
{
"sourceKeys": "window.location.pathname",
"destKeys": "page.path"
},
{
"sourceKeys": "window.location.search",
"destKeys": "page.search"
},
{
"sourceKeys": "window.screen.height",
"destKeys": "screen.height"
},
{
"sourceKeys": "window.screen.width",
"destKeys": "screen.width"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"sourceKeys": "image.src",
"destKeys": "image_url"
},
{
"sourceKeys": "price.amount",
"destKeys": "price"
},
{
"sourceKeys": "product.id",
"destKeys": "product_id"
},
{
"sourceKeys": "product.title",
"destKeys": "variant"
},
{
"sourceKeys": "product.type",
"destKeys": "category"
},
{
"sourceKeys": "product.url",
"destKeys": "url"
},
{
"sourceKeys": "product.vendor",
"destKeys": "brand"
},
{
"sourceKeys": "sku",
"destKeys": "sku"
},
{
"sourceKeys": "title",
"destKeys": "name"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"sourceKeys": "cartLine.merchandise.image.src",
"destKeys": "image_url"
},
{
"sourceKeys": "cartLine.merchandise.price.amount",
"destKeys": "price"
},
{
"sourceKeys": "cartLine.merchandise.product.id",
"destKeys": "product_id"
},
{
"sourceKeys": "cartLine.merchandise.product.title",
"destKeys": "variant"
},
{
"sourceKeys": "cartLine.merchandise.product.type",
"destKeys": "category"
},
{
"sourceKeys": "cartLine.merchandise.product.vendor",
"destKeys": "brand"
},
{
"sourceKeys": "cartLine.merchandise.product.url",
"destKeys": "url"
},
{
"sourceKeys": "cartLine.merchandise.sku",
"destKeys": "sku"
},
{
"sourceKeys": "cartLine.merchandise.title",
"destKeys": "name"
},
{
"sourceKeys": "cartLine.quantity",
"destKeys": "quantity"
}
]
Loading

0 comments on commit d40e772

Please sign in to comment.