fix(SW-2438): change to breakfast buffet always and replace dash with empty string * fix(SW-2438): change to breakfast buffet always and replace dash with empty string * fix(SW-2438): remove none from ageOfChildren Approved-by: Tobias Johansson Approved-by: Matilda Landström
66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
|
|
|
import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
|
|
import {
|
|
TrackingChannelEnum,
|
|
type TrackingSDKHotelInfo,
|
|
type TrackingSDKPageData,
|
|
} from "@/types/components/tracking"
|
|
import type { Lang } from "@/constants/languages"
|
|
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
|
|
|
export function getTracking(
|
|
lang: Lang,
|
|
arrivalDate: Date,
|
|
departureDate: Date,
|
|
adultsInRoom: number[],
|
|
childrenInRoom: ChildrenInRoom,
|
|
hotelId: string,
|
|
hotelName: string,
|
|
noOfRooms: number,
|
|
country: string | undefined,
|
|
hotelCity: string | undefined,
|
|
paramCity: string | undefined,
|
|
bookingCode?: string,
|
|
isRedemption?: boolean
|
|
) {
|
|
const pageTrackingData: TrackingSDKPageData = {
|
|
channel: TrackingChannelEnum.hotelreservation,
|
|
domainLanguage: lang,
|
|
pageId: "select-rate",
|
|
pageName: "hotelreservation|select-rate",
|
|
pageType: "bookingroomsandratespage",
|
|
siteSections: "hotelreservation|select-rate",
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
|
ageOfChildren: childrenInRoom
|
|
?.map((c) => c?.map((k) => k.age).join(",") ?? "")
|
|
.join("|"),
|
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
|
childBedPreference: childrenInRoom
|
|
?.map((c) => c?.map((k) => ChildBedMapEnum[k.bed]).join(",") ?? "")
|
|
.join("|"),
|
|
country,
|
|
departureDate: format(departureDate, "yyyy-MM-dd"),
|
|
duration: differenceInCalendarDays(departureDate, arrivalDate),
|
|
hotelID: hotelId,
|
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
|
noOfAdults: adultsInRoom.join(","),
|
|
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
|
|
noOfRooms,
|
|
region: hotelCity,
|
|
searchTerm: paramCity ?? hotelName,
|
|
searchType: "hotel",
|
|
bookingCode: bookingCode ?? "n/a",
|
|
rewardNight: isRedemption ? "yes" : "no",
|
|
}
|
|
|
|
return {
|
|
hotelsTrackingData,
|
|
pageTrackingData,
|
|
}
|
|
}
|