diff --git a/apps/scandic-web/components/HotelReservation/MyStay/GuaranteeLateArrival/GuaranteeLateArrivalCallback/index.tsx b/apps/scandic-web/components/HotelReservation/MyStay/GuaranteeLateArrival/GuaranteeLateArrivalCallback/index.tsx index 349699b5f..598c86507 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/GuaranteeLateArrival/GuaranteeLateArrivalCallback/index.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/GuaranteeLateArrival/GuaranteeLateArrivalCallback/index.tsx @@ -5,9 +5,13 @@ import { useEffect } from "react" import { PaymentCallbackStatusEnum } from "@/constants/booking" -import { readGlaFromSessionStorage } from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers" +import { + clearGlaSessionStorage, + readGlaFromSessionStorage, +} from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers" import LoadingSpinner from "@/components/LoadingSpinner" import { trackEvent } from "@/utils/tracking/base" +import { buildAncillaries } from "@/utils/tracking/myStay" import { buildAncillaryPackages, @@ -42,22 +46,16 @@ export default function TrackGuarantee({ trackEvent({ event, paymentInfo: { status }, - ancillaries: packages.map((pkg) => ({ - hotelId: selectedAncillary?.hotelId, - productId: pkg.code, - productUnits: pkg.quantity, - productPoints: selectedAncillary?.points, - productDeliveryTime: formData?.deliveryTime, - productPrice: selectedAncillary?.price.total, - currency: selectedAncillary?.price.currency, - productName: selectedAncillary?.title, - productCategory: selectedAncillary?.categoryName, - })), hotelInfo: { hotelId: selectedAncillary?.hotelId, lateArrivalGuarantee: "yes", guaranteedProduct: "room + ancillary", }, + ancillaries: buildAncillaries( + packages, + selectedAncillary, + formData?.deliveryTime + ), }) } @@ -75,6 +73,7 @@ export default function TrackGuarantee({ ...(errorMessage && { errorMessage }), }, }) + clearGlaSessionStorage() } switch (status) { @@ -88,6 +87,7 @@ export default function TrackGuarantee({ guaranteedProduct: "room", }, }) + clearGlaSessionStorage() break case PaymentCallbackStatusEnum.Cancel: diff --git a/apps/scandic-web/utils/tracking/myStay.ts b/apps/scandic-web/utils/tracking/myStay.ts index e2f8b02b0..c19f56856 100644 --- a/apps/scandic-web/utils/tracking/myStay.ts +++ b/apps/scandic-web/utils/tracking/myStay.ts @@ -44,6 +44,36 @@ export function trackGlaSaveCardAttempt( }) } +export function buildAncillaries( + packages: { + code: string + quantity: number + comment?: string + }[], + selectedAncillary: SelectedAncillary | null | undefined, + deliveryTime: string | string[] | null | undefined +) { + return packages.map((pkg) => { + const payedWithCard = pkg.code === selectedAncillary?.id + const payedWithPoints = pkg.code === selectedAncillary?.loyaltyCode + + return { + productId: pkg.code, + productUnits: pkg.quantity, + productDeliveryTime: deliveryTime, + productName: selectedAncillary?.title, + productCategory: selectedAncillary?.categoryName, + ...(payedWithCard && { + productPrice: (selectedAncillary?.price.total ?? 0) * pkg.quantity, + currency: selectedAncillary?.price.currency, + }), + ...(payedWithPoints && { + productPoints: (selectedAncillary?.points ?? 0) * pkg.quantity, + }), + } + }) +} + export function trackGlaAncillaryAttempt( savedCreditCard: CreditCard | undefined, packages: { @@ -60,17 +90,7 @@ export function trackGlaAncillaryAttempt( status: "glacardsaveattempt", type: savedCreditCard?.cardType, }, - ancillaries: packages.map((pkg) => ({ - hotelId: selectedAncillary?.hotelId, - productId: pkg.code, - productUnits: pkg.quantity, - productPoints: selectedAncillary?.points, - productDeliveryTime: deliveryTime, - productPrice: selectedAncillary?.price.total, - currency: selectedAncillary?.price.currency, - productName: selectedAncillary?.title, - productCategory: selectedAncillary?.categoryName, - })), + ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime), hotelInfo: { hotelId: selectedAncillary?.hotelId, lateArrivalGuarantee: "yes", @@ -104,16 +124,7 @@ export function trackAncillarySuccess( status: "glacardsaveconfirmed", type: cardType, }, - ancillaries: packages.map((pkg) => ({ - productId: pkg.code, - productUnits: pkg.quantity, - productPoints: selectedAncillary?.points, - productDeliveryTime: deliveryTime, - productPrice: selectedAncillary?.price.total, - currency: selectedAncillary?.price.currency, - productName: selectedAncillary?.title, - productCategory: selectedAncillary?.categoryName, - })), + ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime), }) } @@ -128,16 +139,7 @@ export function trackAncillaryFailed( ) { trackEvent({ event: "GuaranteeFailAncillary", - ancillaries: packages.map((pkg) => ({ - productId: pkg.code, - productUnits: pkg.quantity, - productPoints: selectedAncillary?.points, - productDeliveryTime: deliveryTime, - productPrice: selectedAncillary?.price.total, - currency: selectedAncillary?.price.currency, - productName: selectedAncillary?.title, - productCategory: selectedAncillary?.categoryName, - })), + ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime), hotelInfo: { hotelId: selectedAncillary?.hotelId, lateArrivalGuarantee: "yes",