Tracking on select hotel and select rate pages
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
||||||
import { notFound } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
import { Lang } from "@/constants/languages"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
import { getLocations } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
@@ -10,11 +12,17 @@ import {
|
|||||||
getHotelReservationQueryParams,
|
getHotelReservationQueryParams,
|
||||||
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { MapModal } from "@/components/MapModal"
|
import { MapModal } from "@/components/MapModal"
|
||||||
|
import TrackingSDK from "@/components/TrackingSDK"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import { fetchAvailableHotels } from "../../utils"
|
import { fetchAvailableHotels } from "../../utils"
|
||||||
|
|
||||||
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
import type { SelectHotelSearchParams } from "@/types/components/hotelReservation/selectHotel/selectHotelSearchParams"
|
||||||
|
import {
|
||||||
|
TrackingChannelEnum,
|
||||||
|
TrackingSDKHotelInfo,
|
||||||
|
TrackingSDKPageData,
|
||||||
|
} from "@/types/components/tracking"
|
||||||
import type { LangParams, PageArgs } from "@/types/params"
|
import type { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|
||||||
export default async function SelectHotelMapPage({
|
export default async function SelectHotelMapPage({
|
||||||
@@ -44,9 +52,8 @@ export default async function SelectHotelMapPage({
|
|||||||
const selectHotelParamsObject =
|
const selectHotelParamsObject =
|
||||||
getHotelReservationQueryParams(selectHotelParams)
|
getHotelReservationQueryParams(selectHotelParams)
|
||||||
const adults = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
|
const adults = selectHotelParamsObject.room[0].adults // TODO: Handle multiple rooms
|
||||||
const children = selectHotelParamsObject.room[0].child
|
const child = selectHotelParamsObject.room[0].child // TODO: Handle multiple rooms
|
||||||
? generateChildrenString(selectHotelParamsObject.room[0].child)
|
const children = child ? generateChildrenString(child) : undefined // TODO: Handle multiple rooms
|
||||||
: undefined // TODO: Handle multiple rooms
|
|
||||||
|
|
||||||
const hotels = await fetchAvailableHotels({
|
const hotels = await fetchAvailableHotels({
|
||||||
cityId: city.id,
|
cityId: city.id,
|
||||||
@@ -56,6 +63,34 @@ export default async function SelectHotelMapPage({
|
|||||||
children,
|
children,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const arrivalDate = new Date(searchParams.fromDate)
|
||||||
|
const departureDate = new Date(searchParams.toDate)
|
||||||
|
|
||||||
|
const pageTrackingData: TrackingSDKPageData = {
|
||||||
|
pageId: "select-hotel",
|
||||||
|
domainLanguage: params.lang as Lang,
|
||||||
|
channel: TrackingChannelEnum["hotelreservation"],
|
||||||
|
pageName: "hotelreservation|select-hotel|mapview",
|
||||||
|
siteSections: "hotelreservation|select-hotel|mapview",
|
||||||
|
pageType: "bookinghotelsmapviewpage",
|
||||||
|
}
|
||||||
|
|
||||||
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
||||||
|
availableResults: hotels.length,
|
||||||
|
searchTerm: searchParams.city,
|
||||||
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
||||||
|
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||||
|
noOfAdults: adults,
|
||||||
|
noOfChildren: child?.length,
|
||||||
|
noOfRooms: 1, // // TODO: Handle multiple rooms
|
||||||
|
duration: differenceInCalendarDays(departureDate, arrivalDate),
|
||||||
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
||||||
|
searchType: "destination",
|
||||||
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
||||||
|
country: hotels?.[0].hotelData.address.country,
|
||||||
|
region: hotels?.[0].hotelData.address.city,
|
||||||
|
}
|
||||||
|
|
||||||
const hotelPins = getHotelPins(hotels)
|
const hotelPins = getHotelPins(hotels)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -66,6 +101,7 @@ export default async function SelectHotelMapPage({
|
|||||||
mapId={googleMapId}
|
mapId={googleMapId}
|
||||||
hotels={hotels}
|
hotels={hotels}
|
||||||
/>
|
/>
|
||||||
|
<TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} />
|
||||||
</MapModal>
|
</MapModal>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ export default async function SelectHotelPage({
|
|||||||
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
||||||
searchType: "destination",
|
searchType: "destination",
|
||||||
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
||||||
country: hotels[0].hotelData.address.country,
|
country: hotels?.[0].hotelData.address.country,
|
||||||
region: hotels[0].hotelData.address.city,
|
region: hotels?.[0].hotelData.address.city,
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
||||||
import { notFound } from "next/navigation"
|
import { notFound } from "next/navigation"
|
||||||
|
|
||||||
|
import { Lang } from "@/constants/languages"
|
||||||
import { dt } from "@/lib/dt"
|
import { dt } from "@/lib/dt"
|
||||||
import {
|
import {
|
||||||
getHotelData,
|
getHotelData,
|
||||||
@@ -14,10 +16,16 @@ import {
|
|||||||
generateChildrenString,
|
generateChildrenString,
|
||||||
getHotelReservationQueryParams,
|
getHotelReservationQueryParams,
|
||||||
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
|
import TrackingSDK from "@/components/TrackingSDK"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
|
import {
|
||||||
|
TrackingChannelEnum,
|
||||||
|
TrackingSDKHotelInfo,
|
||||||
|
TrackingSDKPageData,
|
||||||
|
} from "@/types/components/tracking"
|
||||||
import type { LangParams, PageArgs } from "@/types/params"
|
import type { LangParams, PageArgs } from "@/types/params"
|
||||||
|
|
||||||
export default async function SelectRatePage({
|
export default async function SelectRatePage({
|
||||||
@@ -84,6 +92,46 @@ export default async function SelectRatePage({
|
|||||||
getProfileSafely(),
|
getProfileSafely(),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const arrivalDate = new Date(searchParams.fromDate)
|
||||||
|
const departureDate = new Date(searchParams.toDate)
|
||||||
|
const hotelAttributes = hotelData?.data.attributes
|
||||||
|
|
||||||
|
const roomCategories = hotelData?.included
|
||||||
|
|
||||||
|
const noRoomsAvailable = roomsAvailability?.roomConfigurations.reduce(
|
||||||
|
(acc, room) => {
|
||||||
|
return acc && room.status === "NotAvailable"
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
|
const pageTrackingData: TrackingSDKPageData = {
|
||||||
|
pageId: "select-rate",
|
||||||
|
domainLanguage: params.lang as Lang,
|
||||||
|
channel: TrackingChannelEnum["hotelreservation"],
|
||||||
|
pageName: "hotelreservation|select-rate",
|
||||||
|
siteSections: "hotelreservation|select-rate",
|
||||||
|
pageType: "bookingroomsandratespage",
|
||||||
|
}
|
||||||
|
|
||||||
|
const hotelsTrackingData: TrackingSDKHotelInfo = {
|
||||||
|
searchTerm: searchParams.city,
|
||||||
|
arrivalDate: format(arrivalDate, "yyyy-MM-dd"),
|
||||||
|
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||||
|
noOfAdults: adults,
|
||||||
|
noOfChildren: childrenCount,
|
||||||
|
//childBedPreference // "adults|adults|extra|adults"
|
||||||
|
noOfRooms: 1, // // TODO: Handle multiple rooms
|
||||||
|
duration: differenceInCalendarDays(departureDate, arrivalDate),
|
||||||
|
leadTime: differenceInCalendarDays(arrivalDate, new Date()),
|
||||||
|
searchType: "hotel",
|
||||||
|
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
|
||||||
|
country: hotelAttributes?.address.country,
|
||||||
|
region: hotelAttributes?.address.city,
|
||||||
|
availableResults: roomCategories?.length,
|
||||||
|
//lowestRoomPrice:
|
||||||
|
}
|
||||||
|
|
||||||
if (!roomsAvailability) {
|
if (!roomsAvailability) {
|
||||||
return "No rooms found" // TODO: Add a proper error message
|
return "No rooms found" // TODO: Add a proper error message
|
||||||
}
|
}
|
||||||
@@ -92,24 +140,19 @@ export default async function SelectRatePage({
|
|||||||
return "No hotel data found" // TODO: Add a proper error message
|
return "No hotel data found" // TODO: Add a proper error message
|
||||||
}
|
}
|
||||||
|
|
||||||
const roomCategories = hotelData?.included
|
|
||||||
|
|
||||||
const noRoomsAvailable = roomsAvailability.roomConfigurations.reduce(
|
|
||||||
(acc, room) => {
|
|
||||||
return acc && room.status === "NotAvailable"
|
|
||||||
},
|
|
||||||
true
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HotelInfoCard hotelData={hotelData} noAvailability={noRoomsAvailable} />
|
<HotelInfoCard
|
||||||
|
hotelData={hotelData}
|
||||||
|
noAvailability={!!noRoomsAvailable}
|
||||||
|
/>
|
||||||
<Rooms
|
<Rooms
|
||||||
roomsAvailability={roomsAvailability}
|
roomsAvailability={roomsAvailability}
|
||||||
roomCategories={roomCategories ?? []}
|
roomCategories={roomCategories ?? []}
|
||||||
user={user}
|
user={user}
|
||||||
packages={packages ?? []}
|
packages={packages ?? []}
|
||||||
/>
|
/>
|
||||||
|
<TrackingSDK pageData={pageTrackingData} hotelInfo={hotelsTrackingData} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user