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:
@@ -11,7 +11,7 @@ import { FamilyAndFriendsCodes } from "@/constants/booking"
|
||||
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
|
||||
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
||||
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 { getIntl } from "@/i18n"
|
||||
import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||
@@ -38,18 +38,10 @@ export default async function AlternativeHotelsPage(
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const {
|
||||
adultsInRoom,
|
||||
bookingCode,
|
||||
childrenInRoom,
|
||||
city,
|
||||
cityIdentifier,
|
||||
hotel: isAlternativeFor,
|
||||
noOfRooms,
|
||||
redemption,
|
||||
} = searchDetails
|
||||
|
||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||
if (
|
||||
booking.bookingCode &&
|
||||
FamilyAndFriendsCodes.includes(booking.bookingCode)
|
||||
) {
|
||||
const cookieStore = await cookies()
|
||||
const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
|
||||
|
||||
@@ -64,22 +56,22 @@ export default async function AlternativeHotelsPage(
|
||||
fromDate: booking.fromDate,
|
||||
toDate: booking.toDate,
|
||||
rooms: booking.rooms,
|
||||
isAlternativeFor,
|
||||
bookingCode,
|
||||
city,
|
||||
redemption: !!redemption,
|
||||
isAlternativeFor: searchDetails.hotel,
|
||||
bookingCode: booking.bookingCode,
|
||||
city: searchDetails.city,
|
||||
redemption: !!searchDetails.redemption,
|
||||
})
|
||||
|
||||
const arrivalDate = new Date(booking.fromDate)
|
||||
const departureDate = new Date(booking.toDate)
|
||||
|
||||
const isRedemptionAvailability = redemption
|
||||
const isRedemptionAvailability = searchDetails.redemption
|
||||
? hotels.some(
|
||||
(hotel) => hotel.availability.productType?.redemptions?.length
|
||||
)
|
||||
: false
|
||||
|
||||
const isBookingCodeRateAvailable = bookingCode
|
||||
const isBookingCodeRateAvailable = booking.bookingCode
|
||||
? hotels.some(
|
||||
(hotel) =>
|
||||
hotel.availability.bookingCode &&
|
||||
@@ -87,24 +79,29 @@ export default async function AlternativeHotelsPage(
|
||||
)
|
||||
: false
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||
params.lang,
|
||||
!!isAlternativeFor,
|
||||
const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
|
||||
lang: params.lang,
|
||||
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,
|
||||
departureDate,
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotels?.length ?? 0,
|
||||
booking.hotelId,
|
||||
noOfRooms,
|
||||
hotels?.[0]?.hotel.address.country,
|
||||
hotels?.[0]?.hotel.address.city,
|
||||
cityIdentifier,
|
||||
bookingCode,
|
||||
rooms: booking.rooms,
|
||||
hotelsResult: hotels?.length ?? 0,
|
||||
searchTerm: searchDetails.hotel
|
||||
? booking.hotelId
|
||||
: searchDetails.cityIdentifier,
|
||||
country: hotels?.[0]?.hotel.address.country,
|
||||
hotelCity: hotels?.[0]?.hotel.address.city,
|
||||
bookingCode: booking.bookingCode,
|
||||
isBookingCodeRateAvailable,
|
||||
redemption,
|
||||
isRedemptionAvailability
|
||||
)
|
||||
isRedemption: searchDetails.redemption,
|
||||
isRedemptionAvailable: isRedemptionAvailability,
|
||||
})
|
||||
|
||||
const mapHref = alternativeHotelsMap(params.lang)
|
||||
|
||||
@@ -114,17 +111,17 @@ export default async function AlternativeHotelsPage(
|
||||
defaultMessage: "Alternatives for {value}",
|
||||
},
|
||||
{
|
||||
value: isAlternativeFor.name,
|
||||
value: searchDetails.hotel.name,
|
||||
}
|
||||
)
|
||||
const suspenseKey = stringify(searchParams)
|
||||
return (
|
||||
<>
|
||||
<SelectHotel
|
||||
bookingCode={bookingCode}
|
||||
city={city}
|
||||
bookingCode={booking.bookingCode}
|
||||
city={searchDetails.city}
|
||||
hotels={hotels}
|
||||
isAlternative={!!isAlternativeFor}
|
||||
isAlternative={!!searchDetails.hotel}
|
||||
isBookingCodeRateAvailable={isBookingCodeRateAvailable}
|
||||
mapHref={mapHref}
|
||||
title={title}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { FamilyAndFriendsCodes } from "@/constants/booking"
|
||||
import FnFNotAllowedAlert from "@/components/HotelReservation/FnFNotAllowedAlert/FnFNotAllowedAlert"
|
||||
import SelectHotel from "@/components/HotelReservation/SelectHotel"
|
||||
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 { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||
|
||||
@@ -31,17 +31,10 @@ export default async function SelectHotelPage(
|
||||
|
||||
if (!searchDetails || !searchDetails.city) return notFound()
|
||||
|
||||
const {
|
||||
adultsInRoom,
|
||||
bookingCode,
|
||||
childrenInRoom,
|
||||
city,
|
||||
cityIdentifier,
|
||||
noOfRooms,
|
||||
redemption,
|
||||
} = searchDetails
|
||||
|
||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||
if (
|
||||
booking.bookingCode &&
|
||||
FamilyAndFriendsCodes.includes(booking.bookingCode)
|
||||
) {
|
||||
const cookieStore = await cookies()
|
||||
const isInvalidFNF = cookieStore.get("sc")?.value !== "1"
|
||||
|
||||
@@ -50,26 +43,25 @@ export default async function SelectHotelPage(
|
||||
}
|
||||
}
|
||||
|
||||
const { city, redemption } = searchDetails
|
||||
|
||||
const hotels = await getHotels({
|
||||
fromDate: booking.fromDate,
|
||||
toDate: booking.toDate,
|
||||
rooms: booking.rooms,
|
||||
isAlternativeFor: null,
|
||||
bookingCode,
|
||||
city,
|
||||
bookingCode: booking.bookingCode,
|
||||
city: city,
|
||||
redemption: !!redemption,
|
||||
})
|
||||
|
||||
const arrivalDate = new Date(booking.fromDate)
|
||||
const departureDate = new Date(booking.toDate)
|
||||
|
||||
const isRedemptionAvailability = redemption
|
||||
? hotels.some(
|
||||
(hotel) => hotel.availability.productType?.redemptions?.length
|
||||
)
|
||||
: false
|
||||
|
||||
const isBookingCodeRateAvailable = bookingCode
|
||||
const isBookingCodeRateAvailable = booking.bookingCode
|
||||
? hotels.some(
|
||||
(hotel) =>
|
||||
hotel.availability.bookingCode &&
|
||||
@@ -77,31 +69,33 @@ export default async function SelectHotelPage(
|
||||
)
|
||||
: false
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||
params.lang,
|
||||
false,
|
||||
const arrivalDate = new Date(booking.fromDate)
|
||||
const departureDate = new Date(booking.toDate)
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
|
||||
rooms: booking.rooms,
|
||||
lang: params.lang,
|
||||
pageId: "select-hotel",
|
||||
pageName: "hotelreservation|select-hotel",
|
||||
siteSections: "hotelreservation|select-hotel",
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotels?.length ?? 0,
|
||||
booking.hotelId,
|
||||
noOfRooms,
|
||||
hotels?.[0]?.hotel.address.country,
|
||||
hotels?.[0]?.hotel.address.city,
|
||||
cityIdentifier,
|
||||
bookingCode,
|
||||
hotelsResult: hotels?.length ?? 0,
|
||||
searchTerm: booking.hotelId,
|
||||
country: hotels?.[0]?.hotel.address.country,
|
||||
hotelCity: hotels?.[0]?.hotel.address.city,
|
||||
bookingCode: booking.bookingCode,
|
||||
isBookingCodeRateAvailable,
|
||||
redemption,
|
||||
isRedemptionAvailability
|
||||
)
|
||||
isRedemption: redemption,
|
||||
isRedemptionAvailable: isRedemptionAvailability,
|
||||
})
|
||||
|
||||
const mapHref = selectHotelMap(params.lang)
|
||||
const suspenseKey = stringify(searchParams)
|
||||
return (
|
||||
<>
|
||||
<SelectHotel
|
||||
bookingCode={bookingCode}
|
||||
bookingCode={booking.bookingCode}
|
||||
isBookingCodeRateAvailable={isBookingCodeRateAvailable}
|
||||
city={city}
|
||||
hotels={hotels}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { getHotelSearchDetails } from "@/utils/hotelSearchDetails"
|
||||
|
||||
import { getHotelPins } from "../../HotelCardDialogListing/utils"
|
||||
import { getFiltersFromHotels, getHotels } from "../helpers"
|
||||
import { getTracking } from "./tracking"
|
||||
import { getSelectHotelTracking } from "../tracking"
|
||||
import SelectHotelMap from "."
|
||||
|
||||
import type { SelectHotelMapContainerProps } from "@/types/components/hotelReservation/selectHotel/map"
|
||||
@@ -34,13 +34,9 @@ export async function SelectHotelMapContainer({
|
||||
}
|
||||
|
||||
const {
|
||||
adultsInRoom,
|
||||
bookingCode,
|
||||
childrenInRoom,
|
||||
city,
|
||||
cityIdentifier,
|
||||
hotel: isAlternativeFor,
|
||||
noOfRooms,
|
||||
redemption,
|
||||
} = searchDetails
|
||||
|
||||
@@ -53,7 +49,7 @@ export async function SelectHotelMapContainer({
|
||||
toDate: booking.toDate,
|
||||
rooms: booking.rooms,
|
||||
isAlternativeFor,
|
||||
bookingCode,
|
||||
bookingCode: booking.bookingCode,
|
||||
city,
|
||||
redemption: !!redemption,
|
||||
})
|
||||
@@ -73,29 +69,31 @@ export async function SelectHotelMapContainer({
|
||||
)
|
||||
: false
|
||||
|
||||
const isBookingCodeRateAvailable = bookingCode
|
||||
const isBookingCodeRateAvailable = booking.bookingCode
|
||||
? hotels?.some((hotel) => hotel.availability.bookingCode)
|
||||
: false
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||
const { hotelsTrackingData, pageTrackingData } = getSelectHotelTracking({
|
||||
lang,
|
||||
!!isAlternativeFor,
|
||||
!!isAlternativeHotels,
|
||||
pageId: isAlternativeFor ? "alternative-hotels" : "select-hotel",
|
||||
pageName: isAlternativeHotels
|
||||
? "hotelreservation|alternative-hotels|mapview"
|
||||
: "hotelreservation|select-hotel|mapview",
|
||||
siteSections: isAlternativeHotels
|
||||
? "hotelreservation|altervative-hotels|mapview"
|
||||
: "hotelreservation|select-hotel|mapview",
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotels.length,
|
||||
booking.hotelId,
|
||||
noOfRooms,
|
||||
hotels?.[0]?.hotel.address.country,
|
||||
hotels?.[0]?.hotel.address.city,
|
||||
cityIdentifier,
|
||||
bookingCode,
|
||||
rooms: booking.rooms,
|
||||
hotelsResult: hotels.length,
|
||||
searchTerm: isAlternativeFor ? booking.hotelId : cityIdentifier,
|
||||
country: hotels?.[0]?.hotel.address.country,
|
||||
hotelCity: hotels?.[0]?.hotel.address.city,
|
||||
bookingCode: booking.bookingCode,
|
||||
isBookingCodeRateAvailable,
|
||||
redemption,
|
||||
isRedemptionAvailability
|
||||
)
|
||||
isRedemption: redemption,
|
||||
isRedemptionAvailable: isRedemptionAvailability,
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -106,7 +104,7 @@ export async function SelectHotelMapContainer({
|
||||
hotels={hotels}
|
||||
filterList={filterList}
|
||||
cityCoordinates={cityCoordinates}
|
||||
bookingCode={bookingCode ?? ""}
|
||||
bookingCode={booking.bookingCode}
|
||||
isBookingCodeRateAvailable={isBookingCodeRateAvailable}
|
||||
isAlternativeHotels={isAlternativeHotels}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -13,24 +13,16 @@ import TrackingSDK from "@/components/TrackingSDK"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
import { getValidDates } from "../getValidDates"
|
||||
import { getTracking } from "./tracking"
|
||||
|
||||
import type { ChildrenInRoom } from "@/utils/hotelSearchDetails"
|
||||
import { getSelectRateTracking } from "./tracking"
|
||||
|
||||
export default function Tracking({
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotelId,
|
||||
hotelName,
|
||||
noOfRooms,
|
||||
country,
|
||||
city,
|
||||
}: {
|
||||
adultsInRoom: number[]
|
||||
childrenInRoom: ChildrenInRoom
|
||||
hotelId: string
|
||||
hotelName: string
|
||||
noOfRooms: number
|
||||
country: string
|
||||
city: string
|
||||
}) {
|
||||
@@ -47,22 +39,19 @@ export default function Tracking({
|
||||
const arrivalDate = fromDate.toDate()
|
||||
const departureDate = toDate.toDate()
|
||||
|
||||
const { hotelsTrackingData, pageTrackingData } = getTracking(
|
||||
const { hotelsTrackingData, pageTrackingData } = getSelectRateTracking({
|
||||
lang,
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
adultsInRoom,
|
||||
childrenInRoom,
|
||||
hotelId,
|
||||
hotelName,
|
||||
noOfRooms,
|
||||
country,
|
||||
city,
|
||||
hotelCity: city,
|
||||
paramCity,
|
||||
bookingCode,
|
||||
searchType === SEARCH_TYPE_REDEMPTION,
|
||||
rooms
|
||||
)
|
||||
isRedemption: searchType === SEARCH_TYPE_REDEMPTION,
|
||||
rooms,
|
||||
})
|
||||
|
||||
return (
|
||||
<TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} />
|
||||
|
||||
@@ -13,22 +13,33 @@ import {
|
||||
} from "@/types/components/tracking"
|
||||
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,
|
||||
type SelectRateTrackingInput = {
|
||||
lang: Lang
|
||||
arrivalDate: Date
|
||||
departureDate: Date
|
||||
hotelId: string
|
||||
hotelName: string
|
||||
country: string | undefined
|
||||
hotelCity: string | undefined
|
||||
paramCity: string | undefined
|
||||
bookingCode?: string
|
||||
isRedemption?: boolean
|
||||
rooms?: Room[]
|
||||
) {
|
||||
}
|
||||
|
||||
export function getSelectRateTracking({
|
||||
lang,
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
hotelId,
|
||||
hotelName,
|
||||
country,
|
||||
hotelCity,
|
||||
paramCity,
|
||||
bookingCode,
|
||||
isRedemption = false,
|
||||
rooms = [],
|
||||
}: SelectRateTrackingInput) {
|
||||
const pageTrackingData: TrackingSDKPageData = {
|
||||
channel: TrackingChannelEnum.hotelreservation,
|
||||
domainLanguage: lang,
|
||||
@@ -39,6 +50,13 @@ export function getTracking(
|
||||
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(",") ?? "")
|
||||
@@ -55,7 +73,7 @@ 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: paramCity ?? hotelName,
|
||||
searchType: "hotel",
|
||||
|
||||
@@ -28,11 +28,8 @@ export default async function SelectRatePage({
|
||||
return notFound()
|
||||
}
|
||||
|
||||
const { adultsInRoom, childrenInRoom, hotel, noOfRooms, bookingCode } =
|
||||
searchDetails
|
||||
|
||||
const hotelData = await getHotel({
|
||||
hotelId: hotel.id,
|
||||
hotelId: searchDetails.hotel.id,
|
||||
isCardOnlyPayment: false,
|
||||
language: lang,
|
||||
})
|
||||
@@ -42,10 +39,14 @@ export default async function SelectRatePage({
|
||||
}
|
||||
|
||||
let isInValidFNF = false
|
||||
if (bookingCode && FamilyAndFriendsCodes.includes(bookingCode)) {
|
||||
if (
|
||||
booking.bookingCode &&
|
||||
FamilyAndFriendsCodes.includes(booking.bookingCode)
|
||||
) {
|
||||
const cookieStore = await cookies()
|
||||
isInValidFNF = cookieStore.get("sc")?.value !== "1"
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<HotelInfoCard booking={booking} hotel={hotelData.hotel} />
|
||||
@@ -61,11 +62,8 @@ export default async function SelectRatePage({
|
||||
)}
|
||||
|
||||
<Tracking
|
||||
adultsInRoom={adultsInRoom}
|
||||
childrenInRoom={childrenInRoom}
|
||||
hotelId={hotel.id}
|
||||
hotelName={hotel.name}
|
||||
noOfRooms={noOfRooms}
|
||||
hotelId={searchDetails.hotel.id}
|
||||
hotelName={searchDetails.hotel.name}
|
||||
country={hotelData.hotel.address.country}
|
||||
city={hotelData.hotel.address.city}
|
||||
/>
|
||||
|
||||
@@ -2,7 +2,6 @@ import { notFound } from "next/navigation"
|
||||
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
||||
import { generateChildrenString } from "@scandic-hotels/trpc/routers/hotels/helpers"
|
||||
import {
|
||||
type HotelLocation,
|
||||
isHotelLocation,
|
||||
@@ -15,17 +14,11 @@ import type { BookingSearchType } from "@scandic-hotels/booking-flow/searchType"
|
||||
import type { Child } from "@scandic-hotels/trpc/types/child"
|
||||
|
||||
export type ChildrenInRoom = (Child[] | null)[] | null
|
||||
export type ChildrenInRoomString = (string | null)[] | null
|
||||
|
||||
interface HotelSearchDetails {
|
||||
adultsInRoom: number[]
|
||||
bookingCode?: string
|
||||
childrenInRoom: ChildrenInRoom
|
||||
childrenInRoomString: ChildrenInRoomString
|
||||
city: Location | null
|
||||
cityIdentifier: string | undefined
|
||||
hotel: HotelLocation | null
|
||||
noOfRooms: number
|
||||
redemption?: boolean
|
||||
}
|
||||
|
||||
@@ -37,7 +30,6 @@ export async function getHotelSearchDetails(
|
||||
adults: number
|
||||
childrenInRoom?: Child[]
|
||||
}[]
|
||||
bookingCode?: string
|
||||
searchType?: BookingSearchType
|
||||
},
|
||||
isAlternativeHotels?: boolean
|
||||
@@ -76,30 +68,10 @@ export async function getHotelSearchDetails(
|
||||
if (!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 {
|
||||
adultsInRoom,
|
||||
bookingCode: params.bookingCode ?? undefined,
|
||||
childrenInRoom,
|
||||
childrenInRoomString,
|
||||
city,
|
||||
cityIdentifier,
|
||||
hotel,
|
||||
noOfRooms: rooms?.length ?? 0,
|
||||
redemption: params.searchType === SEARCH_TYPE_REDEMPTION,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user