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: { isSavedCreditCard: !!savedCreditCard, 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: { isSavedCreditCard: !!savedCreditCard, 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, productPoints: ancillary?.points, productCategory: ancillary?.categoryName, }) } if ((quantityWithPoints ?? 0) > 0) { ancillaries.push({ hotelId: ancillary?.hotelId, productId: ancillary?.loyaltyCode, productName: ancillary?.title, productUnits: quantityWithPoints, productPrice: ancillary?.price, productPoints: ancillary?.points, productCategory: ancillary?.categoryName, }) } trackEvent({ event: "addAncillary", ancillaries, }) }