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 { 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}
/>

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 { 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 {

View File

@@ -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} />

View File

@@ -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",

View File

@@ -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}
/>