Files
web/apps/scandic-web/utils/tracking/myStay.ts
Bianca Widstam 77c03905e4 Merged in fix/hide-payment-if-only-points (pull request #1741)
Feat(SW-1943): add new design for pay ancillaries with points

* fix: hide card and payment info if only quantity with points is selected

* feat(SW-1943): add new design for pay ancillaries with points

* feat(SW-1943): add missing translation

* feat(SW-1943): fix rebase

* feat(SW-1943): remove console log


Approved-by: Linus Flood
Approved-by: Matilda Landström
2025-04-10 06:18:02 +00:00

207 lines
5.1 KiB
TypeScript

import { trackEvent } from "./base"
import type { SelectedAncillary } from "@/types/components/myPages/myStay/ancillaries"
import type { PackageSchema } from "@/types/trpc/routers/booking/confirmation"
import type { CreditCard } from "@/types/user"
export function trackCancelStay(hotelId: string, bnr: string) {
trackEvent({
event: "BookingCancellations",
hotelInfo: {
hotelId: hotelId,
bnr: bnr,
},
})
}
export function trackMyStayPageLink(ctaName: string) {
trackEvent({
event: "confirmationPageLinks",
cta: {
name: ctaName,
},
})
}
type LateArrivalGuarantee = "mandatory" | "yes" | "no" | "na"
export function trackGlaSaveCardAttempt(
hotelId: string,
savedCreditCard: CreditCard | undefined,
lateArrivalGuarantee: LateArrivalGuarantee
) {
trackEvent({
event: "glaCardSaveAttempt",
hotelInfo: {
hotelId,
lateArrivalGuarantee,
guaranteedProduct: "room",
},
paymentInfo: {
status: "glacardsaveattempt",
type: savedCreditCard?.cardType,
},
})
}
export function trackGlaAncillaryAttempt(
savedCreditCard: CreditCard | undefined,
packages: {
code: string
quantity: number
comment: string | undefined
}[],
selectedAncillary: SelectedAncillary | null,
deliveryTime: string | undefined
) {
trackEvent({
event: "GuaranteeAttemptAncillary",
paymentInfo: {
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,
productName: selectedAncillary?.title,
productCategory: selectedAncillary?.categoryName,
})),
lateArrivalGuarantee: "yes",
guaranteedProduct: "room + ancillary",
})
}
export function trackAncillarySuccess(
confirmationNumber: string,
packages: {
code: string
quantity: number
comment?: string
}[],
deliveryTime: string | null | undefined,
guaranteedProduct: string,
selectedAncillary: SelectedAncillary | null,
cardType?: string,
roomTypeCode?: string
) {
trackEvent({
event: "AncillarySuccess",
hotelInfo: {
bnr: confirmationNumber,
roomTypeCode: roomTypeCode,
},
paymentInfo: {
status: "glacardsaveconfirmed",
type: cardType,
},
ancillaries: packages.map((pkg) => ({
productId: pkg.code,
productUnits: pkg.quantity,
productPoints: selectedAncillary?.points,
productDeliveryTime: deliveryTime,
productPrice: selectedAncillary?.price,
productName: selectedAncillary?.title,
productCategory: selectedAncillary?.categoryName,
})),
lateArrivalGuarantee: "yes",
guaranteedProduct: guaranteedProduct,
})
}
export function trackAncillaryFailed(
packages: {
code: string
quantity: number
comment?: string
}[],
deliveryTime: string | null | undefined,
selectedAncillary: SelectedAncillary | null
) {
trackEvent({
event: "GuaranteeFailAncillary",
ancillaries: packages.map((pkg) => ({
productId: pkg.code,
productUnits: pkg.quantity,
productPoints: selectedAncillary?.points,
productDeliveryTime: deliveryTime,
productPrice: selectedAncillary?.price,
productName: selectedAncillary?.title,
productCategory: selectedAncillary?.categoryName,
})),
lateArrivalGuarantee: "yes",
guaranteedProduct: "ancillary",
})
}
export function trackViewAncillary(ancillary: SelectedAncillary) {
trackEvent({
event: "viewAncillary",
ancillaries: [
{
hotelId: ancillary.hotelId,
productId: ancillary.id,
productName: ancillary.title,
productCategory: ancillary.categoryName,
},
],
})
}
export function trackRemoveAncillary(
ancillary: PackageSchema,
hotelId: string,
deliveryTime?: string
) {
trackEvent({
event: "removeAncillary",
ancillaries: [
{
hotelId,
productId: ancillary.code,
productPrice: ancillary.totalPrice,
productPoints: ancillary.points,
productUnits: ancillary.totalUnit,
productType: ancillary.type,
productDeliveryTime: deliveryTime,
},
],
})
}
export function trackAddAncillary(
ancillary: SelectedAncillary | null,
quantityWithCard: number | null,
quantityWithPoints: number | null
) {
const ancillaries = []
if ((quantityWithCard ?? 0) > 0) {
ancillaries.push({
hotelId: ancillary?.hotelId,
productId: ancillary?.id,
productName: ancillary?.title,
productUnits: quantityWithCard,
productPrice: ancillary?.price,
productCategory: ancillary?.categoryName,
})
}
if ((quantityWithPoints ?? 0) > 0) {
ancillaries.push({
hotelId: ancillary?.hotelId,
productId: ancillary?.loyaltyCode,
productName: ancillary?.title,
productUnits: quantityWithPoints,
productPoints: ancillary?.points,
productCategory: ancillary?.categoryName,
})
}
trackEvent({
event: "addAncillary",
ancillaries,
})
}