Feat/SW-1997 tracking gla my stay ancillaries * feat(SW-1996): tracking gla my stay * feat(SW-1996): update gla tracking * feat(SW-1996): fix comment * feat(SW-1997): add tracking for gla my stay and ancillaries * feat(SW-1997): rebase master * feat(SW-1997): fix duplicate import * feat(SW-1997): add hotelId and category for ancillaries, and add more tracking * feat(SW-1997): remove commments and fix spelling mistake * feat(SW-1997): if addAncillary failed, but guarantee is successful, default to card in booking Approved-by: Niclas Edenvin
211 lines
5.3 KiB
TypeScript
211 lines
5.3 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: {
|
|
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,
|
|
})
|
|
}
|