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:
Anton Gunnarsson
2025-08-06 08:35:48 +00:00
parent 7fb082f712
commit 41efb3a7b3
9 changed files with 184 additions and 274 deletions

View File

@@ -11,7 +11,7 @@ import { FamilyAndFriendsCodes } from "@/constants/booking"
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert" import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
import SelectHotel from "@/components/HotelReservation/SelectHotel" import SelectHotel from "@/components/HotelReservation/SelectHotel"
import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers" import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers"
import { getTracking } from "@/components/HotelReservation/SelectHotel/tracking" import { getSelectHotelTracking } from "@/components/HotelReservation/SelectHotel/tracking"
import TrackingSDK from "@/components/TrackingSDK" import TrackingSDK from "@/components/TrackingSDK"
import { getIntl } from "@/i18n" import { getIntl } from "@/i18n"
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails" import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
@@ -38,18 +38,10 @@ export default async function AlternativeHotelsPage(
return notFound() return notFound()
} }
const { if (
adultsInRoom, booking.bookingCode &&
bookingCode, FamilyAndFriendsCodes.includes(booking.bookingCode)
childrenInRoom, ) {
city,
cityIdentifier,
hotel: isAlternativeFor,
noOfRooms,
redemption,
} = searchDetails
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
const cookieStore = await cookies() const cookieStore = await cookies()
const isInvalidFNF = cookieStore.get("sc")?.value !== "1" const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
@@ -64,22 +56,22 @@ export default async function AlternativeHotelsPage(
fromDate: booking.fromDate, fromDate: booking.fromDate,
toDate: booking.toDate, toDate: booking.toDate,
rooms: booking.rooms, rooms: booking.rooms,
isAlternativeFor, isAlternativeFor: searchDetails.hotel,
bookingCode, bookingCode: booking.bookingCode,
city, city: searchDetails.city,
redemption: !!redemption, redemption: !!searchDetails.redemption,
}) })
const arrivalDate = new Date(booking.fromDate) const arrivalDate = new Date(booking.fromDate)
const departureDate = new Date(booking.toDate) const departureDate = new Date(booking.toDate)
const isRedemptionAvailability = redemption const isRedemptionAvailability = searchDetails.redemption
? hotels.some( ? hotels.some(
(hotel) => hotel.availability.productType?.redemptions?.length (hotel) => hotel.availability.productType?.redemptions?.length
) )
: false : false
const isBookingCodeRateAvailable = bookingCode const isBookingCodeRateAvailable = booking.bookingCode
? hotels.some( ? hotels.some(
(hotel) => (hotel) =>
hotel.availability.bookingCode && hotel.availability.bookingCode &&
@@ -87,24 +79,29 @@ export default async function AlternativeHotelsPage(
) )
: false : false
const { hotelsTrackingData, pageTrackingData } = getTracking( const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
params.lang, lang: params.lang,
!!isAlternativeFor, pageId: searchDetails.hotel ? "alternative-hotels" : "select-hotel",
pageName: searchDetails.hotel
? "hotelreservation|alternative-hotels"
: "hotelreservation|select-hotel",
siteSections: searchDetails.hotel
? "hotelreservation|alternative-hotels"
: "hotelreservation|select-hotel",
arrivalDate, arrivalDate,
departureDate, departureDate,
adultsInRoom, rooms: booking.rooms,
childrenInRoom, hotelsResult: hotels?.length ?? 0,
hotels?.length ?? 0, searchTerm: searchDetails.hotel
booking.hotelId, ? booking.hotelId
noOfRooms, : searchDetails.cityIdentifier,
hotels?.[0]?.hotel.address.country, country: hotels?.[0]?.hotel.address.country,
hotels?.[0]?.hotel.address.city, hotelCity: hotels?.[0]?.hotel.address.city,
cityIdentifier, bookingCode: booking.bookingCode,
bookingCode,
isBookingCodeRateAvailable, isBookingCodeRateAvailable,
redemption, isRedemption: searchDetails.redemption,
isRedemptionAvailability isRedemptionAvailable: isRedemptionAvailability,
) })
const mapHref = alternativeHotelsMap(params.lang) const mapHref = alternativeHotelsMap(params.lang)
@@ -114,17 +111,17 @@ export default async function AlternativeHotelsPage(
defaultMessage: "Alternatives for {value}", defaultMessage: "Alternatives for {value}",
}, },
{ {
value: isAlternativeFor.name, value: searchDetails.hotel.name,
} }
) )
const suspenseKey = stringify(searchParams) const suspenseKey = stringify(searchParams)
return ( return (
<> <>
<SelectHotel <SelectHotel
bookingCode={bookingCode} bookingCode={booking.bookingCode}
city={city} city={searchDetails.city}
hotels={hotels} hotels={hotels}
isAlternative={!!isAlternativeFor} isAlternative={!!searchDetails.hotel}
isBookingCodeRateAvailable={isBookingCodeRateAvailable} isBookingCodeRateAvailable={isBookingCodeRateAvailable}
mapHref={mapHref} mapHref={mapHref}
title={title} title={title}

View File

@@ -11,7 +11,7 @@ import { FamilyAndFriendsCodes } from "@/constants/booking"
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert" import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
import SelectHotel from "@/components/HotelReservation/SelectHotel" import SelectHotel from "@/components/HotelReservation/SelectHotel"
import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers" import { getHotels } from "@/components/HotelReservation/SelectHotel/helpers"
import { getTracking } from "@/components/HotelReservation/SelectHotel/tracking" import { getSelectHotelTracking } from "@/components/HotelReservation/SelectHotel/tracking"
import TrackingSDK from "@/components/TrackingSDK" import TrackingSDK from "@/components/TrackingSDK"
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails" import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
@@ -31,17 +31,10 @@ export default async function SelectHotelPage(
if (!searchDetails || !searchDetails.city) return notFound() if (!searchDetails || !searchDetails.city) return notFound()
const { if (
adultsInRoom, booking.bookingCode &&
bookingCode, FamilyAndFriendsCodes.includes(booking.bookingCode)
childrenInRoom, ) {
city,
cityIdentifier,
noOfRooms,
redemption,
} = searchDetails
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
const cookieStore = await cookies() const cookieStore = await cookies()
const isInvalidFNF = cookieStore.get("sc")?.value !== "1" const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
@@ -50,26 +43,25 @@ export default async function SelectHotelPage(
} }
} }
const { city, redemption } = searchDetails
const hotels = await getHotels({ const hotels = await getHotels({
fromDate: booking.fromDate, fromDate: booking.fromDate,
toDate: booking.toDate, toDate: booking.toDate,
rooms: booking.rooms, rooms: booking.rooms,
isAlternativeFor: null, isAlternativeFor: null,
bookingCode, bookingCode: booking.bookingCode,
city, city: city,
redemption: !!redemption, redemption: !!redemption,
}) })
const arrivalDate = new Date(booking.fromDate)
const departureDate = new Date(booking.toDate)
const isRedemptionAvailability = redemption const isRedemptionAvailability = redemption
? hotels.some( ? hotels.some(
(hotel) => hotel.availability.productType?.redemptions?.length (hotel) => hotel.availability.productType?.redemptions?.length
) )
: false : false
const isBookingCodeRateAvailable = bookingCode const isBookingCodeRateAvailable = booking.bookingCode
? hotels.some( ? hotels.some(
(hotel) => (hotel) =>
hotel.availability.bookingCode && hotel.availability.bookingCode &&
@@ -77,31 +69,33 @@ export default async function SelectHotelPage(
) )
: false : false
const { hotelsTrackingData, pageTrackingData } = getTracking( const arrivalDate = new Date(booking.fromDate)
params.lang, const departureDate = new Date(booking.toDate)
false,
const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
rooms: booking.rooms,
lang: params.lang,
pageId: "select-hotel",
pageName: "hotelreservation|select-hotel",
siteSections: "hotelreservation|select-hotel",
arrivalDate, arrivalDate,
departureDate, departureDate,
adultsInRoom, hotelsResult: hotels?.length ?? 0,
childrenInRoom, searchTerm: booking.hotelId,
hotels?.length ?? 0, country: hotels?.[0]?.hotel.address.country,
booking.hotelId, hotelCity: hotels?.[0]?.hotel.address.city,
noOfRooms, bookingCode: booking.bookingCode,
hotels?.[0]?.hotel.address.country,
hotels?.[0]?.hotel.address.city,
cityIdentifier,
bookingCode,
isBookingCodeRateAvailable, isBookingCodeRateAvailable,
redemption, isRedemption: redemption,
isRedemptionAvailability isRedemptionAvailable: isRedemptionAvailability,
) })
const mapHref = selectHotelMap(params.lang) const mapHref = selectHotelMap(params.lang)
const suspenseKey = stringify(searchParams) const suspenseKey = stringify(searchParams)
return ( return (
<> <>
<SelectHotel <SelectHotel
bookingCode={bookingCode} bookingCode={booking.bookingCode}
isBookingCodeRateAvailable={isBookingCodeRateAvailable} isBookingCodeRateAvailable={isBookingCodeRateAvailable}
city={city} city={city}
hotels={hotels} hotels={hotels}

View File

@@ -11,7 +11,7 @@ import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
import { getHotelPins } from "../../HotelCardDialogListing/utils" import { getHotelPins } from "../../HotelCardDialogListing/utils"
import { getFiltersFromHotels, getHotels } from "../helpers" import { getFiltersFromHotels, getHotels } from "../helpers"
import { getTracking } from "./tracking" import { getSelectHotelTracking } from "../tracking"
import SelectHotelMap from "." import SelectHotelMap from "."
import type { SelectHotelMapContainerProps } from "@/types/components/hotelReservation/selectHotel/map" import type { SelectHotelMapContainerProps } from "@/types/components/hotelReservation/selectHotel/map"
@@ -34,13 +34,9 @@ export async function SelectHotelMapContainer({
} }
const { const {
adultsInRoom,
bookingCode,
childrenInRoom,
city, city,
cityIdentifier, cityIdentifier,
hotel: isAlternativeFor, hotel: isAlternativeFor,
noOfRooms,
redemption, redemption,
} = searchDetails } = searchDetails
@@ -53,7 +49,7 @@ export async function SelectHotelMapContainer({
toDate: booking.toDate, toDate: booking.toDate,
rooms: booking.rooms, rooms: booking.rooms,
isAlternativeFor, isAlternativeFor,
bookingCode, bookingCode: booking.bookingCode,
city, city,
redemption: !!redemption, redemption: !!redemption,
}) })
@@ -73,29 +69,31 @@ export async function SelectHotelMapContainer({
) )
: false : false
const isBookingCodeRateAvailable = bookingCode const isBookingCodeRateAvailable = booking.bookingCode
? hotels?.some((hotel) => hotel.availability.bookingCode) ? hotels?.some((hotel) => hotel.availability.bookingCode)
: false : false
const { hotelsTrackingData, pageTrackingData } = getTracking( const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
lang, lang,
!!isAlternativeFor, pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
!!isAlternativeHotels, pageName: isAlternativeHotels
? "hotelreservation|alternative-hotels|mapview"
: "hotelreservation|select-hotel|mapview",
siteSections: isAlternativeHotels
? "hotelreservation|altervative-hotels|mapview"
: "hotelreservation|select-hotel|mapview",
arrivalDate, arrivalDate,
departureDate, departureDate,
adultsInRoom, rooms: booking.rooms,
childrenInRoom, hotelsResult: hotels.length,
hotels.length, searchTerm: isAlternativeFor ? booking.hotelId : cityIdentifier,
booking.hotelId, country: hotels?.[0]?.hotel.address.country,
noOfRooms, hotelCity: hotels?.[0]?.hotel.address.city,
hotels?.[0]?.hotel.address.country, bookingCode: booking.bookingCode,
hotels?.[0]?.hotel.address.city,
cityIdentifier,
bookingCode,
isBookingCodeRateAvailable, isBookingCodeRateAvailable,
redemption, isRedemption: redemption,
isRedemptionAvailability isRedemptionAvailable: isRedemptionAvailability,
) })
return ( return (
<> <>
@@ -106,7 +104,7 @@ export async function SelectHotelMapContainer({
hotels={hotels} hotels={hotels}
filterList={filterList} filterList={filterList}
cityCoordinates={cityCoordinates} cityCoordinates={cityCoordinates}
bookingCode={bookingCode ?? ""} bookingCode={booking.bookingCode}
isBookingCodeRateAvailable={isBookingCodeRateAvailable} isBookingCodeRateAvailable={isBookingCodeRateAvailable}
isAlternativeHotels={isAlternativeHotels} isAlternativeHotels={isAlternativeHotels}
/> />

View File

@@ -1,77 +0,0 @@
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,
isAlternativeHotels: 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?: boolean,
isRedemption?: boolean,
isRedemptionAvailability?: boolean
) {
const pageTrackingData: TrackingSDKPageData = {
channel: TrackingChannelEnum["hotelreservation"],
domainLanguage: lang,
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
pageName: isAlternativeHotels
? "hotelreservation|alternative-hotels|mapview"
: "hotelreservation|select-hotel|mapview",
pageType: "bookinghotelsmapviewpage",
siteSections: isAlternativeHotels
? "hotelreservation|altervative-hotels|mapview"
: "hotelreservation|select-hotel|mapview",
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,
bookingCode: bookingCode ? bookingCode : "n/a",
bookingCodeAvailability: isBookingCodeRateAvailable ? "true" : "false",
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,
rewardNight: isRedemption ? "yes" : "no",
rewardNightAvailability: isRedemptionAvailability ? "true" : "false",
searchTerm: isAlternativeFor ? hotelId : (paramCity as string),
searchType: "destination",
}
return {
hotelsTrackingData,
pageTrackingData,
}
}

View File

@@ -4,6 +4,7 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import type { Lang } from "@scandic-hotels/common/constants/language" import type { Lang } from "@scandic-hotels/common/constants/language"
import type { SelectHotelBooking } from "@/types/components/hotelReservation/selectHotel/selectHotel"
import { import {
TrackingChannelEnum, TrackingChannelEnum,
type TrackingSDKHotelInfo, type TrackingSDKHotelInfo,
@@ -11,44 +12,68 @@ import {
} from "@/types/components/tracking" } from "@/types/components/tracking"
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails" import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
export function getTracking( type SelectHotelTrackingInput = {
lang: Lang, lang: Lang
isAlternativeFor: boolean, pageId: string
arrivalDate: Date, pageName: string
departureDate: Date, siteSections: string
adultsInRoom: number[], arrivalDate: Date
childrenInRoom: ChildrenInRoom, departureDate: Date
hotelsResult: number, rooms: SelectHotelBooking["rooms"]
hotelId: string | undefined, hotelsResult: number
noOfRooms: number, country: string | undefined
country: string | undefined, hotelCity: string | undefined
hotelCity: string | undefined, bookingCode?: string
paramCity: string | undefined, searchTerm?: string
bookingCode?: string, isBookingCodeRateAvailable?: boolean
isRedemption?: boolean
isRedemptionAvailable?: boolean
}
export function getSelectHotelTracking({
lang,
pageId,
pageName,
siteSections,
arrivalDate,
departureDate,
rooms,
hotelsResult,
country,
hotelCity,
searchTerm,
bookingCode,
isBookingCodeRateAvailable = false, isBookingCodeRateAvailable = false,
isRedemption?: boolean, isRedemption = false,
isRedemptionAvailable = false isRedemptionAvailable = false,
) { }: SelectHotelTrackingInput) {
const pageTrackingData: TrackingSDKPageData = { const pageTrackingData: TrackingSDKPageData = {
channel: TrackingChannelEnum["hotelreservation"], channel: TrackingChannelEnum["hotelreservation"],
domainLanguage: lang, domainLanguage: lang,
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel", pageId,
pageName: isAlternativeFor pageName,
? "hotelreservation|alternative-hotels"
: "hotelreservation|select-hotel",
pageType: "bookinghotelspage", pageType: "bookinghotelspage",
siteSections: isAlternativeFor siteSections,
? "hotelreservation|alternative-hotels"
: "hotelreservation|select-hotel",
siteVersion: "new-web", 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 = { const hotelsTrackingData: TrackingSDKHotelInfo = {
ageOfChildren: childrenInRoom ageOfChildren: childrenInRoom
?.map((c) => c?.map((k) => k.age).join(",") ?? "") ?.map((c) => c?.map((k) => k.age).join(",") ?? "")
.join("|"), .join("|"),
arrivalDate: format(arrivalDate, "yyyy-MM-dd"), arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
availableResults: hotelsResult, availableResults: hotelsResult,
bookingCode: bookingCode ?? "n/a",
bookingCodeAvailability: bookingCode
? isBookingCodeRateAvailable.toString()
: undefined,
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday", bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
childBedPreference: childrenInRoom childBedPreference: childrenInRoom
?.map((c) => c?.map((k) => ChildBedMapEnum[k.bed]).join(",") ?? "") ?.map((c) => c?.map((k) => ChildBedMapEnum[k.bed]).join(",") ?? "")
@@ -59,16 +84,12 @@ export function getTracking(
leadTime: differenceInCalendarDays(arrivalDate, new Date()), leadTime: differenceInCalendarDays(arrivalDate, new Date()),
noOfAdults: adultsInRoom.join(","), noOfAdults: adultsInRoom.join(","),
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","), noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
noOfRooms, noOfRooms: rooms?.length ?? 0,
region: hotelCity, region: hotelCity,
searchTerm: isAlternativeFor ? hotelId : (paramCity as string),
searchType: "destination",
bookingCode: bookingCode ?? "n/a",
bookingCodeAvailability: bookingCode
? isBookingCodeRateAvailable.toString()
: undefined,
rewardNight: isRedemption ? "yes" : "no", rewardNight: isRedemption ? "yes" : "no",
rewardNightAvailability: isRedemptionAvailable.toString(), rewardNightAvailability: isRedemptionAvailable.toString(),
searchTerm,
searchType: "destination",
} }
return { return {

View File

@@ -13,24 +13,16 @@ import TrackingSDK from "@/components/TrackingSDK"
import useLang from "@/hooks/useLang" import useLang from "@/hooks/useLang"
import { getValidDates } from "../getValidDates" import { getValidDates } from "../getValidDates"
import { getTracking } from "./tracking" import { getSelectRateTracking } from "./tracking"
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
export default function Tracking({ export default function Tracking({
adultsInRoom,
childrenInRoom,
hotelId, hotelId,
hotelName, hotelName,
noOfRooms,
country, country,
city, city,
}: { }: {
adultsInRoom: number[]
childrenInRoom: ChildrenInRoom
hotelId: string hotelId: string
hotelName: string hotelName: string
noOfRooms: number
country: string country: string
city: string city: string
}) { }) {
@@ -47,22 +39,19 @@ export default function Tracking({
const arrivalDate = fromDate.toDate() const arrivalDate = fromDate.toDate()
const departureDate = toDate.toDate() const departureDate = toDate.toDate()
const { hotelsTrackingData, pageTrackingData } = getTracking( const { hotelsTrackingData, pageTrackingData } = getSelectRateTracking({
lang, lang,
arrivalDate, arrivalDate,
departureDate, departureDate,
adultsInRoom,
childrenInRoom,
hotelId, hotelId,
hotelName, hotelName,
noOfRooms,
country, country,
city, hotelCity: city,
paramCity, paramCity,
bookingCode, bookingCode,
searchType === SEARCH_TYPE_REDEMPTION, isRedemption: searchType === SEARCH_TYPE_REDEMPTION,
rooms rooms,
) })
return ( return (
<TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} /> <TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} />

View File

@@ -13,22 +13,33 @@ import {
} from "@/types/components/tracking" } from "@/types/components/tracking"
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails" import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
export function getTracking( type SelectRateTrackingInput = {
lang: Lang, lang: Lang
arrivalDate: Date, arrivalDate: Date
departureDate: Date, departureDate: Date
adultsInRoom: number[], hotelId: string
childrenInRoom: ChildrenInRoom, hotelName: string
hotelId: string, country: string | undefined
hotelName: string, hotelCity: string | undefined
noOfRooms: number, paramCity: string | undefined
country: string | undefined, bookingCode?: string
hotelCity: string | undefined, isRedemption?: boolean
paramCity: string | undefined,
bookingCode?: string,
isRedemption?: boolean,
rooms?: Room[] rooms?: Room[]
) { }
export function getSelectRateTracking({
lang,
arrivalDate,
departureDate,
hotelId,
hotelName,
country,
hotelCity,
paramCity,
bookingCode,
isRedemption = false,
rooms = [],
}: SelectRateTrackingInput) {
const pageTrackingData: TrackingSDKPageData = { const pageTrackingData: TrackingSDKPageData = {
channel: TrackingChannelEnum.hotelreservation, channel: TrackingChannelEnum.hotelreservation,
domainLanguage: lang, domainLanguage: lang,
@@ -39,6 +50,13 @@ export function getTracking(
siteVersion: "new-web", 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 = { const hotelsTrackingData: TrackingSDKHotelInfo = {
ageOfChildren: childrenInRoom ageOfChildren: childrenInRoom
?.map((c) => c?.map((k) => k.age).join(",") ?? "") ?.map((c) => c?.map((k) => k.age).join(",") ?? "")
@@ -55,7 +73,7 @@ export function getTracking(
leadTime: differenceInCalendarDays(arrivalDate, new Date()), leadTime: differenceInCalendarDays(arrivalDate, new Date()),
noOfAdults: adultsInRoom.join(","), noOfAdults: adultsInRoom.join(","),
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","), noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
noOfRooms, noOfRooms: rooms?.length ?? 0,
region: hotelCity, region: hotelCity,
searchTerm: paramCity ?? hotelName, searchTerm: paramCity ?? hotelName,
searchType: "hotel", searchType: "hotel",

View File

@@ -28,11 +28,8 @@ export default async function SelectRatePage({
return notFound() return notFound()
} }
const { adultsInRoom, childrenInRoom, hotel, noOfRooms, bookingCode } =
searchDetails
const hotelData = await getHotel({ const hotelData = await getHotel({
hotelId: hotel.id, hotelId: searchDetails.hotel.id,
isCardOnlyPayment: false, isCardOnlyPayment: false,
language: lang, language: lang,
}) })
@@ -42,10 +39,14 @@ export default async function SelectRatePage({
} }
let isInValidFNF = false let isInValidFNF = false
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) { if (
booking.bookingCode &&
FamilyAndFriendsCodes.includes(booking.bookingCode)
) {
const cookieStore = await cookies() const cookieStore = await cookies()
isInValidFNF = cookieStore.get("sc")?.value !== "1" isInValidFNF = cookieStore.get("sc")?.value !== "1"
} }
return ( return (
<> <>
<HotelInfoCard booking={booking} hotel={hotelData.hotel} /> <HotelInfoCard booking={booking} hotel={hotelData.hotel} />
@@ -61,11 +62,8 @@ export default async function SelectRatePage({
)} )}
<Tracking <Tracking
adultsInRoom={adultsInRoom} hotelId={searchDetails.hotel.id}
childrenInRoom={childrenInRoom} hotelName={searchDetails.hotel.name}
hotelId={hotel.id}
hotelName={hotel.name}
noOfRooms={noOfRooms}
country={hotelData.hotel.address.country} country={hotelData.hotel.address.country}
city={hotelData.hotel.address.city} city={hotelData.hotel.address.city}
/> />

View File

@@ -2,7 +2,6 @@ import { notFound } from "next/navigation"
import { safeTry } from "@scandic-hotels/common/utils/safeTry" import { safeTry } from "@scandic-hotels/common/utils/safeTry"
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking" import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
import { generateChildrenString } from "@scandic-hotels/trpc/routers/hotels/helpers"
import { import {
type HotelLocation, type HotelLocation,
isHotelLocation, isHotelLocation,
@@ -15,17 +14,11 @@ import type { BookingSearchType } from "@scandic-hotels/booking-flow/searchType"
import type { Child } from "@scandic-hotels/trpc/types/child" import type { Child } from "@scandic-hotels/trpc/types/child"
export type ChildrenInRoom = (Child[] | null)[] | null export type ChildrenInRoom = (Child[] | null)[] | null
export type ChildrenInRoomString = (string | null)[] | null
interface HotelSearchDetails { interface HotelSearchDetails {
adultsInRoom: number[]
bookingCode?: string
childrenInRoom: ChildrenInRoom
childrenInRoomString: ChildrenInRoomString
city: Location | null city: Location | null
cityIdentifier: string | undefined cityIdentifier: string | undefined
hotel: HotelLocation | null hotel: HotelLocation | null
noOfRooms: number
redemption?: boolean redemption?: boolean
} }
@@ -37,7 +30,6 @@ export async function getHotelSearchDetails(
adults: number adults: number
childrenInRoom?: Child[] childrenInRoom?: Child[]
}[] }[]
bookingCode?: string
searchType?: BookingSearchType searchType?: BookingSearchType
}, },
isAlternativeHotels?: boolean isAlternativeHotels?: boolean
@@ -76,30 +68,10 @@ export async function getHotelSearchDetails(
if (!city && !hotel) return notFound() if (!city && !hotel) return notFound()
if (isAlternativeHotels && (!city || !hotel)) return notFound() if (isAlternativeHotels && (!city || !hotel)) return notFound()
let adultsInRoom: number[] = []
let childrenInRoom: ChildrenInRoom = null
let childrenInRoomString: ChildrenInRoomString = null
const { rooms } = params
if (rooms?.length) {
adultsInRoom = rooms.map((room) => room.adults ?? 0)
childrenInRoom = rooms.map((room) => room.childrenInRoom ?? null)
childrenInRoomString = rooms.map((room) =>
room.childrenInRoom ? generateChildrenString(room.childrenInRoom) : null
)
}
return { return {
adultsInRoom,
bookingCode: params.bookingCode ?? undefined,
childrenInRoom,
childrenInRoomString,
city, city,
cityIdentifier, cityIdentifier,
hotel, hotel,
noOfRooms: rooms?.length ?? 0,
redemption: params.searchType === SEARCH_TYPE_REDEMPTION, redemption: params.searchType === SEARCH_TYPE_REDEMPTION,
} }
} }