Skip to content

Commit

Permalink
Adding condition to only update DL when cart flow is membership
Browse files Browse the repository at this point in the history
  • Loading branch information
pgilmore-phi committed Oct 22, 2024
1 parent d6121ee commit 5f6580d
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions blocks/thank-you/thank-you.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ export default async function decorate() {

const h1 = document.querySelector('h1');
const {
firstName, lastName,
cartFlow, firstName, lastName,
} = getOwnerDetails;
const isMembershipFlow = cartFlow === 2;
const { petSummaries } = getPurchaseSummaryDetails;
const contentColumn = document.querySelector('.thank-you-purchase .columns > div:nth-child(1) > div');

Expand All @@ -146,21 +147,23 @@ export default async function decorate() {

contentColumn.appendChild(ul);

// update analyics values
totalShipping += pet.nonInsurancePetSummary.shipping;
productTypes.push(pet.nonInsurancePetSummary.membership.itemName);
// push each item object to items array
dlItems.push({
item_name: pet.nonInsurancePetSummary.membership.itemName,
currency: currencyValue,
discount: pet.nonInsurancePetSummary.discount,
item_category: 'membership', // membership
item_variant: '', // okay to be left empty
price: pet.nonInsurancePetSummary.amount,
quantity: pet.nonInsurancePetSummary.membership.quantity,
microchip_number: pet.microChipNumber,
product_type: pet.nonInsurancePetSummary.membership.itemName,
});
// update analyics values if cart flow is membership
if (isMembershipFlow) {
totalShipping += pet.nonInsurancePetSummary.shipping;
productTypes.push(pet.nonInsurancePetSummary.membership.itemName);
// push each item object to items array
dlItems.push({
item_name: pet.nonInsurancePetSummary.membership.itemName,
currency: currencyValue,
discount: pet.nonInsurancePetSummary.discount,
item_category: 'membership', // membership
item_variant: '', // okay to be left empty
price: pet.nonInsurancePetSummary.amount,
quantity: pet.nonInsurancePetSummary.membership.quantity,
microchip_number: pet.microChipNumber,
product_type: pet.nonInsurancePetSummary.membership.itemName,
});
}
});

// build sub-total, tax, and total of items purchased
Expand All @@ -186,22 +189,24 @@ export default async function decorate() {

contentColumn.appendChild(totals);

const trackingData = {
ecommerce: {
transaction_id: externalTransactionID,
affiliation: '24petwatch',
value: summary.totalDueToday,
tax: summary.salesTaxes,
shipping: totalShipping ? totalShipping.toFixed(2) : '0.00',
currency: currencyValue,
payment_type: paymentMethod,
product_type: productTypes.join(', '),
items: dlItems,
},
};

// send the GTM event
trackGTMEvent('purchase', trackingData);
if (isMembershipFlow) {
const trackingData = {
ecommerce: {
transaction_id: externalTransactionID,
affiliation: '24petwatch',
value: summary.totalDueToday,
tax: summary.salesTaxes,
shipping: totalShipping ? totalShipping.toFixed(2) : '0.00',
currency: currencyValue,
payment_type: paymentMethod,
product_type: productTypes.join(', '),
items: dlItems,
},
};

// send the GTM event
trackGTMEvent('purchase', trackingData);
}

// Salesforce Upsert
async function setUpsertToSalesforce(email) {
Expand Down

0 comments on commit 5f6580d

Please sign in to comment.