Merged in feat/sw-3207-refactor-select-hotel-tracking (pull request #2587)
feat(SW-3207): Refactor select-hotel tracking * Refactor select-hotel tracking Approved-by: Bianca Widstam
This commit is contained in:
@@ -4,6 +4,7 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
import type { SelectHotelBooking } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
type TrackingSDKHotelInfo,
|
||||
@@ -11,44 +12,68 @@ import {
|
||||
} 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,
|
||||
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?: boolean,
|
||||
isRedemptionAvailable = false
|
||||
) {
|
||||
isRedemption = false,
|
||||
isRedemptionAvailable = false,
|
||||
}: SelectHotelTrackingInput) {
|
||||
const pageTrackingData: TrackingSDKPageData = {
|
||||
channel: TrackingChannelEnum["hotelreservation"],
|
||||
domainLanguage: lang,
|
||||
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
|
||||
pageName: isAlternativeFor
|
||||
? "hotelreservation|alternative-hotels"
|
||||
: "hotelreservation|select-hotel",
|
||||
pageId,
|
||||
pageName,
|
||||
pageType: "bookinghotelspage",
|
||||
siteSections: isAlternativeFor
|
||||
? "hotelreservation|alternative-hotels"
|
||||
: "hotelreservation|select-hotel",
|
||||
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(",") ?? "")
|
||||
@@ -59,16 +84,12 @@ export function getTracking(
|
||||
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
||||
noOfAdults: adultsInRoom.join(","),
|
||||
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
|
||||
noOfRooms,
|
||||
noOfRooms: rooms?.length ?? 0,
|
||||
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(),
|
||||
searchTerm,
|
||||
searchType: "destination",
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user