Skip to content

Commit b31a31b

Browse files
committed
FIX damian suggestions
1 parent 064c40c commit b31a31b

File tree

2 files changed

+5
-12
lines changed
  • src
    • app/[country]/[locale]/(storefront)/account/orders/[id]
    • lib/analytics

2 files changed

+5
-12
lines changed

src/app/[country]/[locale]/(storefront)/account/orders/[id]/page.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { usePathname } from "next/navigation";
1414
import { use, useEffect, useState } from "react";
1515
import { PaymentIcon } from "react-svg-credit-card-payment-icons";
1616
import { ChevronLeftIcon, ImagePlaceholderIcon } from "@/components/icons";
17-
import { trackPurchase } from "@/lib/analytics/gtm";
1817
import { getOrder } from "@/lib/data/orders";
1918
import { getCardIconType, getCardLabel } from "@/lib/utils/credit-card";
2019
import { extractBasePath } from "@/lib/utils/path";
@@ -283,9 +282,6 @@ export default function OrderDetailPage({ params }: OrderDetailPageProps) {
283282
async function loadOrder() {
284283
const orderData = await getOrder(id);
285284
setOrder(orderData);
286-
if (orderData && orderData.state === "complete") {
287-
trackPurchase(orderData);
288-
}
289285
setLoading(false);
290286
}
291287
loadOrder();

src/lib/analytics/gtm.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,9 @@ export function mapLineItemToGA4Item(
118118
item.item_list_name = options.listName;
119119
}
120120

121-
if (
122-
lineItem.compare_at_amount &&
123-
parseFloat(lineItem.compare_at_amount) > parseFloat(lineItem.price)
124-
) {
125-
item.discount =
126-
parseFloat(lineItem.compare_at_amount) - parseFloat(lineItem.price);
121+
const promoTotal = parseFloat(lineItem.promo_total);
122+
if (promoTotal < 0) {
123+
item.discount = Math.abs(promoTotal);
127124
}
128125

129126
return item;
@@ -267,7 +264,7 @@ export function trackAddPaymentInfo(
267264

268265
export function trackPurchase(order: StoreOrder): void {
269266
const key = `gtm_purchase_${order.number}`;
270-
if (typeof window !== "undefined" && sessionStorage.getItem(key)) {
267+
if (typeof window !== "undefined" && localStorage.getItem(key)) {
271268
return;
272269
}
273270

@@ -286,7 +283,7 @@ export function trackPurchase(order: StoreOrder): void {
286283
});
287284

288285
if (typeof window !== "undefined") {
289-
sessionStorage.setItem(key, "1");
286+
localStorage.setItem(key, "1");
290287
}
291288
}
292289

0 commit comments

Comments
 (0)