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

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