Merged in fix/SW-1997-tracking-correct-price-or-points (pull request #1869)
fix(SW-1997): only add points or card if payed with * fix(SW-1997): only add points or card if payed with * fix(SW-1997): use buildAncillaries function Approved-by: Michael Zetterberg
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user