Skip to content

Commit

Permalink
feat: shopify: ecom version option
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Nov 27, 2023
1 parent 6d6dafc commit fc2ef8c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions deviceModeInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var rudderTracking = (function () {
let pagePathArr = "";
let userId;
let enableClientIdentifierEvents;
let version = "v0";

const cartItemMapping = [
{ dest: "product_id", src: "product_id" },
Expand Down Expand Up @@ -64,7 +65,7 @@ var rudderTracking = (function () {
/**
* This function checks if Customer wants us to send Identify Event
*/
function isClientSideIdentifierEventsEnabled() {
function getSourceConfig() {
const authKey = btoa("writeKey_placeHolder" + ":");
const webhookUrl = "configUrl_placeholder/sourceConfig";
return new Promise(function (resolve, reject) {
Expand All @@ -79,15 +80,11 @@ var rudderTracking = (function () {
xhr.setRequestHeader('Authorization', 'Basic ' + authKey);
},
success: function (response) {
if (response.source?.config?.disableClientSideIdentifier === true) {
resolve(false)
} else {
resolve(true);
}
resolve(response);
},
error: function (xhr, status, error) {
console.debug("Couldn't fetch Source Config due error: " + xhr.responseJSON.message);
resolve(true);
resolve({});
}
})
});
Expand Down Expand Up @@ -152,14 +149,16 @@ var rudderTracking = (function () {
checkAndSendRudderIdentifier();// sending rudderIdentifier periodically after this
}
});
isClientSideIdentifierEventsEnabled().then(response => {
if (!!response) {
getSourceConfig().then(response => {
if (response.source?.config?.disableClientSideIdentifier === true) {
enableClientIdentifierEvents = false;
} else {
enableClientIdentifierEvents = true;
identifyUser();
} else {
enableClientIdentifierEvents = false;
}
});
version = response.source?.config?.version || "v0";
})

productListViews();
trackPageEvent();
trackNamedPageView();
Expand Down Expand Up @@ -803,7 +802,9 @@ var rudderTracking = (function () {

// mapping seems fine
function addToCart() {
rudderanalytics.track("Product Added", this);
if (version === "v0") {
rudderanalytics.track("Product Added", this);
}
}

// triggered on clicking buy now
Expand Down

0 comments on commit fc2ef8c

Please sign in to comment.