Merged in fix/SW-2853-tracking-breakfast-ancillaries (pull request #2188)
fix(SW-2853): tracking for breakfast ancillaries * fix(SW-2853): tracking for breakfast ancillaries * fix(SW-2853): viewAncillary event fix for breakfast * fix(SW-2853): pr comment spread room facilities Approved-by: Tobias Johansson
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { trackEvent } from "./base"
|
||||
|
||||
import type { SelectedAncillary } from "@/types/components/myPages/myStay/ancillaries"
|
||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import type { Room } from "@/types/stores/my-stay"
|
||||
import type { PackageSchema } from "@/types/trpc/routers/booking/confirmation"
|
||||
import type { CreditCard } from "@/types/user"
|
||||
import type { BreakfastData } from "@/stores/my-stay/add-ancillary-flow"
|
||||
|
||||
export function trackCancelStay(hotelId: string, bnr: string) {
|
||||
trackEvent({
|
||||
@@ -45,7 +48,7 @@ export function trackGlaSaveCardAttempt(
|
||||
})
|
||||
}
|
||||
|
||||
export function buildAncillaries(
|
||||
export function buildAncillariesTracking(
|
||||
packages: {
|
||||
code: string
|
||||
quantity: number
|
||||
@@ -57,11 +60,14 @@ export function buildAncillaries(
|
||||
return packages.map((pkg) => {
|
||||
const payedWithCard = pkg.code === selectedAncillary?.id
|
||||
const payedWithPoints = pkg.code === selectedAncillary?.loyaltyCode
|
||||
const ancillaryDeliveryTime = selectedAncillary?.requiresDeliveryTime
|
||||
? deliveryTime
|
||||
: undefined
|
||||
|
||||
return {
|
||||
productId: pkg.code,
|
||||
productUnits: pkg.quantity,
|
||||
productDeliveryTime: deliveryTime,
|
||||
productDeliveryTime: ancillaryDeliveryTime,
|
||||
productName: selectedAncillary?.title,
|
||||
productCategory: selectedAncillary?.categoryName,
|
||||
...(payedWithCard && {
|
||||
@@ -83,7 +89,8 @@ export function trackGlaAncillaryAttempt(
|
||||
comment: string | undefined
|
||||
}[],
|
||||
selectedAncillary: SelectedAncillary | null,
|
||||
deliveryTime: string | undefined
|
||||
deliveryTime: string | undefined,
|
||||
breakfastData: BreakfastData | null
|
||||
) {
|
||||
trackEvent({
|
||||
event: "GuaranteeAttemptAncillary",
|
||||
@@ -91,7 +98,9 @@ export function trackGlaAncillaryAttempt(
|
||||
status: "glacardsaveattempt",
|
||||
type: savedCreditCard?.cardType,
|
||||
},
|
||||
ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime),
|
||||
ancillaries: breakfastData
|
||||
? buildBreakfastTracking(breakfastData, selectedAncillary?.hotelId)
|
||||
: buildAncillariesTracking(packages, selectedAncillary, deliveryTime),
|
||||
hotelInfo: {
|
||||
hotelId: selectedAncillary?.hotelId,
|
||||
lateArrivalGuarantee: "yes",
|
||||
@@ -110,6 +119,7 @@ export function trackAncillarySuccess(
|
||||
deliveryTime: string | null | undefined,
|
||||
guaranteedProduct: string,
|
||||
selectedAncillary: SelectedAncillary | null,
|
||||
breakfastData: BreakfastData | null,
|
||||
cardType?: string,
|
||||
roomTypeCode?: string
|
||||
) {
|
||||
@@ -125,7 +135,9 @@ export function trackAncillarySuccess(
|
||||
status: "glacardsaveconfirmed",
|
||||
type: cardType,
|
||||
},
|
||||
ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime),
|
||||
ancillaries: breakfastData
|
||||
? buildBreakfastTracking(breakfastData, selectedAncillary?.hotelId)
|
||||
: buildAncillariesTracking(packages, selectedAncillary, deliveryTime),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -136,11 +148,14 @@ export function trackAncillaryFailed(
|
||||
comment?: string
|
||||
}[],
|
||||
deliveryTime: string | null | undefined,
|
||||
selectedAncillary: SelectedAncillary | null
|
||||
selectedAncillary: SelectedAncillary | null,
|
||||
breakfastData: BreakfastData | null
|
||||
) {
|
||||
trackEvent({
|
||||
event: "GuaranteeFailAncillary",
|
||||
ancillaries: buildAncillaries(packages, selectedAncillary, deliveryTime),
|
||||
ancillaries: breakfastData
|
||||
? buildBreakfastTracking(breakfastData, selectedAncillary?.hotelId)
|
||||
: buildAncillariesTracking(packages, selectedAncillary, deliveryTime),
|
||||
hotelInfo: {
|
||||
hotelId: selectedAncillary?.hotelId,
|
||||
lateArrivalGuarantee: "yes",
|
||||
@@ -149,47 +164,129 @@ export function trackAncillaryFailed(
|
||||
})
|
||||
}
|
||||
|
||||
export function trackViewAncillary(ancillary: SelectedAncillary) {
|
||||
export function buildBreakfastTracking(
|
||||
breakfastData: BreakfastData,
|
||||
hotelId?: number
|
||||
) {
|
||||
const items = []
|
||||
|
||||
if (breakfastData.nrOfAdults) {
|
||||
items.push({
|
||||
hotelId,
|
||||
productId: BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST,
|
||||
productName: "Breakfast",
|
||||
productUnits: breakfastData.nrOfAdults * breakfastData.nrOfNights,
|
||||
productPrice:
|
||||
breakfastData.priceAdult *
|
||||
breakfastData.nrOfAdults *
|
||||
breakfastData.nrOfNights,
|
||||
currency: breakfastData.currency,
|
||||
productCategory: "Food",
|
||||
})
|
||||
}
|
||||
|
||||
if (breakfastData.nrOfPayingChildren) {
|
||||
items.push({
|
||||
hotelId,
|
||||
productId: BreakfastPackageEnum.ANCILLARY_CHILD_PAYING_BREAKFAST,
|
||||
productName: "Breakfast",
|
||||
productUnits: breakfastData.nrOfPayingChildren * breakfastData.nrOfNights,
|
||||
productPrice:
|
||||
breakfastData.priceChild *
|
||||
breakfastData.nrOfPayingChildren *
|
||||
breakfastData.nrOfNights,
|
||||
currency: breakfastData.currency,
|
||||
productCategory: "Food",
|
||||
})
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
export function trackViewAncillary(
|
||||
ancillary: SelectedAncillary,
|
||||
booking: Room
|
||||
) {
|
||||
const { hotelId, id, title, categoryName } = ancillary
|
||||
const isBreakfast = id === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
|
||||
const hasPayingChildren = booking.childrenAges.some((age) => age >= 4)
|
||||
|
||||
const ancillaries = [
|
||||
{
|
||||
hotelId,
|
||||
productId: id,
|
||||
productName: title,
|
||||
productCategory: categoryName,
|
||||
},
|
||||
]
|
||||
|
||||
if (isBreakfast && hasPayingChildren) {
|
||||
ancillaries.push({
|
||||
hotelId,
|
||||
productId: BreakfastPackageEnum.ANCILLARY_CHILD_PAYING_BREAKFAST,
|
||||
productName: title,
|
||||
productCategory: categoryName,
|
||||
})
|
||||
}
|
||||
|
||||
trackEvent({
|
||||
event: "viewAncillary",
|
||||
ancillaries: [
|
||||
{
|
||||
hotelId: ancillary.hotelId,
|
||||
productId: ancillary.id,
|
||||
productName: ancillary.title,
|
||||
productCategory: ancillary.categoryName,
|
||||
},
|
||||
],
|
||||
ancillaries,
|
||||
})
|
||||
}
|
||||
|
||||
export function trackRemoveAncillary(
|
||||
ancillary: PackageSchema,
|
||||
hotelId: string,
|
||||
deliveryTime?: string
|
||||
deliveryTime?: string,
|
||||
addedBreakfastPackages?: PackageSchema[]
|
||||
) {
|
||||
const isBreakfastPackage =
|
||||
ancillary.code === BreakfastPackageEnum.ANCILLARY_REGULAR_BREAKFAST
|
||||
const isPoints = ancillary.currency === CurrencyEnum.POINTS
|
||||
const packagesWithoutFreeChildBreakfast = addedBreakfastPackages?.filter(
|
||||
(p) => p.code !== BreakfastPackageEnum.FREE_CHILD_BREAKFAST
|
||||
)
|
||||
|
||||
const ancillaries = isBreakfastPackage
|
||||
? (packagesWithoutFreeChildBreakfast?.map((pkg) => ({
|
||||
hotelId,
|
||||
productId: pkg.code,
|
||||
productPrice: pkg.totalPrice,
|
||||
productUnits: pkg.totalUnit,
|
||||
productType: pkg.type,
|
||||
})) ?? [])
|
||||
: [
|
||||
{
|
||||
hotelId,
|
||||
productId: ancillary.code,
|
||||
productPrice: isPoints ? 0 : ancillary.totalPrice,
|
||||
productPoints: isPoints ? ancillary.totalPrice : 0,
|
||||
productUnits: ancillary.totalUnit,
|
||||
productType: ancillary.type,
|
||||
productDeliveryTime: deliveryTime,
|
||||
},
|
||||
]
|
||||
|
||||
trackEvent({
|
||||
event: "removeAncillary",
|
||||
ancillaries: [
|
||||
{
|
||||
hotelId,
|
||||
productId: ancillary.code,
|
||||
productPrice: isPoints ? 0 : ancillary.totalPrice,
|
||||
productPoints: isPoints ? ancillary.totalPrice : 0,
|
||||
productUnits: ancillary.totalUnit,
|
||||
productType: ancillary.type,
|
||||
productDeliveryTime: deliveryTime,
|
||||
},
|
||||
],
|
||||
ancillaries,
|
||||
})
|
||||
}
|
||||
|
||||
export function trackAddAncillary(
|
||||
ancillary: SelectedAncillary | null,
|
||||
quantityWithCard: number | null,
|
||||
quantityWithPoints: number | null
|
||||
quantityWithPoints: number | null,
|
||||
breakfastData: BreakfastData | null
|
||||
) {
|
||||
if (breakfastData) {
|
||||
return trackEvent({
|
||||
event: "addAncillary",
|
||||
ancillaries: buildBreakfastTracking(breakfastData, ancillary?.hotelId),
|
||||
})
|
||||
}
|
||||
|
||||
const ancillaries = []
|
||||
if ((quantityWithCard ?? 0) > 0) {
|
||||
ancillaries.push({
|
||||
|
||||
Reference in New Issue
Block a user