feat(SW-2873): Move select-hotel to booking flow * crude setup of select-hotel in partner-sas * wip * Fix linting * restructure tracking files * Remove dependency on trpc in tracking hooks * Move pageview tracking to common * Fix some lint and import issues * Add AlternativeHotelsPage * Add SelectHotelMapPage * Add AlternativeHotelsMapPage * remove next dependency in tracking store * Remove dependency on react in tracking hooks * move isSameBooking to booking-flow * Inject searchParamsComparator into tracking store * Move useTrackHardNavigation to common * Move useTrackSoftNavigation to common * Add TrackingSDK to partner-sas * call serverclient in layout * Remove unused css * Update types * Move HotelPin type * Fix todos * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Fix component Approved-by: Joakim Jäderberg
105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
|
|
|
import {
|
|
TrackingChannelEnum,
|
|
type TrackingSDKHotelInfo,
|
|
type TrackingSDKPageData,
|
|
} from "@scandic-hotels/common/tracking/types"
|
|
import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
import type { Child } from "@scandic-hotels/trpc/types/child"
|
|
|
|
import type { SelectHotelBooking } from "../utils/url"
|
|
|
|
type ChildrenInRoom = (Child[] | null)[] | null
|
|
|
|
type SelectHotelTrackingInput = {
|
|
lang: Lang
|
|
pageId: string
|
|
pageName: string
|
|
siteSections: string
|
|
arrivalDate: Date
|
|
departureDate: Date
|
|
rooms: SelectHotelBooking["rooms"]
|
|
hotelsResult: number
|
|
country: string | undefined
|
|
hotelCity: string | undefined
|
|
bookingCode?: string
|
|
searchTerm?: string
|
|
isBookingCodeRateAvailable?: boolean
|
|
isRedemption?: boolean
|
|
isRedemptionAvailable?: boolean
|
|
}
|
|
|
|
export function getSelectHotelTracking({
|
|
lang,
|
|
pageId,
|
|
pageName,
|
|
siteSections,
|
|
arrivalDate,
|
|
departureDate,
|
|
rooms,
|
|
hotelsResult,
|
|
country,
|
|
hotelCity,
|
|
searchTerm,
|
|
bookingCode,
|
|
isBookingCodeRateAvailable = false,
|
|
isRedemption = false,
|
|
isRedemptionAvailable = false,
|
|
}: SelectHotelTrackingInput): {
|
|
hotelsTrackingData: TrackingSDKHotelInfo
|
|
pageTrackingData: TrackingSDKPageData
|
|
} {
|
|
const pageTrackingData: TrackingSDKPageData = {
|
|
channel: TrackingChannelEnum["hotelreservation"],
|
|
domainLanguage: lang,
|
|
pageId,
|
|
pageName,
|
|
pageType: "bookinghotelspage",
|
|
siteSections,
|
|
siteVersion: "new-web",
|
|
}
|
|
|
|
let adultsInRoom: number[] = []
|
|
let childrenInRoom: ChildrenInRoom = null
|
|
if (rooms?.length) {
|
|
adultsInRoom = rooms.map((room) => room.adults ?? 0)
|
|
childrenInRoom = rooms.map((room) => room.childrenInRoom ?? null)
|
|
}
|
|
|
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
|
ageOfChildren: childrenInRoom
|
|
?.map((c) => c?.map((k) => k.age).join(",") ?? "")
|
|
.join("|"),
|
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
|
availableResults: hotelsResult,
|
|
bookingCode: bookingCode ?? "n/a",
|
|
bookingCodeAvailability: bookingCode
|
|
? isBookingCodeRateAvailable.toString()
|
|
: undefined,
|
|
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: rooms?.length ?? 0,
|
|
region: hotelCity,
|
|
rewardNight: isRedemption ? "yes" : "no",
|
|
rewardNightAvailability: isRedemptionAvailable.toString(),
|
|
searchTerm,
|
|
searchType: "destination",
|
|
}
|
|
|
|
return {
|
|
hotelsTrackingData,
|
|
pageTrackingData,
|
|
}
|
|
}
|