feat(SW-2863): Move contentstack router to trpc package * Add exports to packages and lint rule to prevent relative imports * Add env to trpc package * Add eslint to trpc package * Apply lint rules * Use direct imports from trpc package * Add lint-staged config to trpc * Move lang enum to common * Restructure trpc package folder structure * WIP first step * update internal imports in trpc * Fix most errors in scandic-web Just 100 left... * Move Props type out of trpc * Fix CategorizedFilters types * Move more schemas in hotel router * Fix deps * fix getNonContentstackUrls * Fix import error * Fix entry error handling * Fix generateMetadata metrics * Fix alertType enum * Fix duplicated types * lint:fix * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package * Fix broken imports * Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package Approved-by: Linus Flood
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
|
|
|
import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
|
|
import {
|
|
TrackingChannelEnum,
|
|
type TrackingSDKHotelInfo,
|
|
type TrackingSDKPageData,
|
|
} from "@/types/components/tracking"
|
|
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
|
|
|
export function getTracking(
|
|
lang: Lang,
|
|
isAlternativeFor: boolean,
|
|
arrivalDate: Date,
|
|
departureDate: Date,
|
|
adultsInRoom: number[],
|
|
childrenInRoom: ChildrenInRoom,
|
|
hotelsResult: number,
|
|
hotelId: string | undefined,
|
|
noOfRooms: number,
|
|
country: string | undefined,
|
|
hotelCity: string | undefined,
|
|
paramCity: string | undefined,
|
|
bookingCode?: string,
|
|
isBookingCodeRateAvailable = false,
|
|
isRedemption?: boolean,
|
|
isRedemptionAvailable = false
|
|
) {
|
|
const pageTrackingData: TrackingSDKPageData = {
|
|
channel: TrackingChannelEnum["hotelreservation"],
|
|
domainLanguage: lang,
|
|
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
|
|
pageName: isAlternativeFor
|
|
? "hotelreservation|alternative-hotels"
|
|
: "hotelreservation|select-hotel",
|
|
pageType: "bookinghotelspage",
|
|
siteSections: isAlternativeFor
|
|
? "hotelreservation|alternative-hotels"
|
|
: "hotelreservation|select-hotel",
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
|
ageOfChildren: childrenInRoom
|
|
?.map((c) => c?.map((k) => k.age).join(",") ?? "")
|
|
.join("|"),
|
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
|
availableResults: hotelsResult,
|
|
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),
|
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
|
noOfAdults: adultsInRoom.join(","),
|
|
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
|
|
noOfRooms,
|
|
region: hotelCity,
|
|
searchTerm: isAlternativeFor ? hotelId : (paramCity as string),
|
|
searchType: "destination",
|
|
bookingCode: bookingCode ?? "n/a",
|
|
bookingCodeAvailability: bookingCode
|
|
? isBookingCodeRateAvailable.toString()
|
|
: undefined,
|
|
rewardNight: isRedemption ? "yes" : "no",
|
|
rewardNightAvailability: isRedemptionAvailable.toString(),
|
|
}
|
|
|
|
return {
|
|
hotelsTrackingData,
|
|
pageTrackingData,
|
|
}
|
|
}
|