Merged in fix/BOOK-459-tracking-search (pull request #2984)

fix(BOOK-459): update searchTerm to city or hotelname

* fix(BOOK-459): update searchTerm to city or hotelname


Approved-by: Erik Tiekstra
This commit is contained in:
Bianca Widstam
2025-10-22 14:34:59 +00:00
parent acdc3dcec1
commit 76c353058b
17 changed files with 40 additions and 35 deletions

View File

@@ -7,7 +7,6 @@ import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK"
import { useBookingFlowConfig } from "../../../bookingFlowConfig/bookingFlowConfigContext" import { useBookingFlowConfig } from "../../../bookingFlowConfig/bookingFlowConfigContext"
import { clearPaymentInfoSessionStorage } from "../../../components/EnterDetails/Payment/helpers" import { clearPaymentInfoSessionStorage } from "../../../components/EnterDetails/Payment/helpers"
import useLang from "../../../hooks/useLang" import useLang from "../../../hooks/useLang"
import { useSearchHistory } from "../../../hooks/useSearchHistory"
import { useBookingConfirmationStore } from "../../../stores/booking-confirmation" import { useBookingConfirmationStore } from "../../../stores/booking-confirmation"
import { getTracking } from "./tracking" import { getTracking } from "./tracking"
@@ -37,9 +36,6 @@ export default function BookingConfirmationTracking({
sessionStorage.setItem("loadedBookingConfirmationRefId", refId) sessionStorage.setItem("loadedBookingConfirmationRefId", refId)
}, [refId]) }, [refId])
const searchHistory = useSearchHistory()
const searchTerm = searchHistory.searchHistory[0]?.name
let trackingData = null let trackingData = null
if (bookingRooms.every(Boolean)) { if (bookingRooms.every(Boolean)) {
@@ -49,8 +45,7 @@ export default function BookingConfirmationTracking({
bookingConfirmation.booking, bookingConfirmation.booking,
bookingConfirmation.hotel, bookingConfirmation.hotel,
rooms, rooms,
config, config
searchTerm
) )
} }

View File

@@ -64,8 +64,7 @@ export function getTracking(
booking: BookingConfirmation["booking"], booking: BookingConfirmation["booking"],
hotel: BookingConfirmation["hotel"], hotel: BookingConfirmation["hotel"],
rooms: Room[], rooms: Room[],
config: Pick<BookingFlowConfig, "bookingCodeEnabled">, config: Pick<BookingFlowConfig, "bookingCodeEnabled">
searchTerm?: string
) { ) {
const arrivalDate = new Date(booking.checkInDate) const arrivalDate = new Date(booking.checkInDate)
const departureDate = new Date(booking.checkOutDate) const departureDate = new Date(booking.checkOutDate)
@@ -160,7 +159,7 @@ export function getTracking(
points: booking.roomPoints > 0 ? booking.roomPoints : undefined, points: booking.roomPoints > 0 ? booking.roomPoints : undefined,
roomPrice: rooms.reduce((total, room) => total + room.roomPrice, 0), roomPrice: rooms.reduce((total, room) => total + room.roomPrice, 0),
roomTypeCode: rooms.map((r) => r.roomTypeCode ?? "").join(","), roomTypeCode: rooms.map((r) => r.roomTypeCode ?? "").join(","),
searchTerm, searchTerm: hotel.name,
searchType: "hotel", searchType: "hotel",
specialRoomType: rooms specialRoomType: rooms
.map((room) => getSpecialRoomType(room.packages)) .map((room) => getSpecialRoomType(room.packages))

View File

@@ -10,6 +10,7 @@ import { useSessionId } from "@scandic-hotels/common/hooks/useSessionId"
import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition" import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition"
import { Alert } from "@scandic-hotels/design-system/Alert" import { Alert } from "@scandic-hotels/design-system/Alert"
import { trackNoAvailability } from "@scandic-hotels/tracking/NoAvailabilityTracking" import { trackNoAvailability } from "@scandic-hotels/tracking/NoAvailabilityTracking"
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode" import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
import useLang from "../../../../hooks/useLang" import useLang from "../../../../hooks/useLang"
@@ -169,6 +170,7 @@ export default function BookingAlert({ isVisible = false }: BookingAlertProps) {
function useNoAvailabilityTracking() { function useNoAvailabilityTracking() {
const { fromDate, toDate, hotelId, bookingCode, searchType, rooms } = const { fromDate, toDate, hotelId, bookingCode, searchType, rooms } =
useEnterDetailsStore((state) => state.booking) useEnterDetailsStore((state) => state.booking)
const hotelName = useEnterDetailsStore((state) => state.hotelName)
const lang = useLang() const lang = useLang()
const sessionId = useSessionId() const sessionId = useSessionId()
@@ -186,12 +188,13 @@ function useNoAvailabilityTracking() {
trackNoAvailability({ trackNoAvailability({
specialRoomType, specialRoomType,
lang, lang,
searchTerm: hotelId, searchTerm: hotelName,
fromDate, fromDate,
toDate, toDate,
hotelId, hotelId,
noOfRooms: rooms.length, noOfRooms: rooms.length,
searchType, searchType: "hotel",
rewardNight: searchType === SEARCH_TYPE_REDEMPTION ? "yes" : "no",
bookingCode: bookingCode ?? "n/a", bookingCode: bookingCode ?? "n/a",
pageId: "details", pageId: "details",
pageName: "hotelreservation|details", pageName: "hotelreservation|details",
@@ -203,9 +206,10 @@ function useNoAvailabilityTracking() {
[ [
specialRoomType, specialRoomType,
lang, lang,
hotelId, hotelName,
fromDate, fromDate,
toDate, toDate,
hotelId,
rooms.length, rooms.length,
searchType, searchType,
bookingCode, bookingCode,

View File

@@ -3,7 +3,6 @@
import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK" import { TrackingSDK } from "@scandic-hotels/tracking/TrackingSDK"
import { useBookingFlowConfig } from "../../../bookingFlowConfig/bookingFlowConfigContext" import { useBookingFlowConfig } from "../../../bookingFlowConfig/bookingFlowConfigContext"
import { useSearchHistory } from "../../../hooks/useSearchHistory"
import { useEnterDetailsStore } from "../../../stores/enter-details" import { useEnterDetailsStore } from "../../../stores/enter-details"
import { getTracking } from "./tracking" import { getTracking } from "./tracking"
@@ -33,8 +32,6 @@ export default function EnterDetailsTrackingWrapper({
breakfastPackages: state.breakfastPackages, breakfastPackages: state.breakfastPackages,
})) }))
const config = useBookingFlowConfig() const config = useBookingFlowConfig()
const searchHistory = useSearchHistory()
const searchTerm = searchHistory.searchHistory[0]?.name
const { hotelsTrackingData, pageTrackingData, ancillaries } = getTracking( const { hotelsTrackingData, pageTrackingData, ancillaries } = getTracking(
booking, booking,
@@ -44,8 +41,7 @@ export default function EnterDetailsTrackingWrapper({
lang, lang,
storedRooms, storedRooms,
breakfastPackages, breakfastPackages,
config, config
searchTerm
) )
return ( return (

View File

@@ -36,8 +36,7 @@ export function getTracking(
lang: Lang, lang: Lang,
storedRooms: RoomState[], storedRooms: RoomState[],
breakfastPackages: BreakfastPackages, breakfastPackages: BreakfastPackages,
config: Pick<BookingFlowConfig, "bookingCodeEnabled">, config: Pick<BookingFlowConfig, "bookingCodeEnabled">
searchTerm?: string
) { ) {
const arrivalDate = new Date(booking.fromDate) const arrivalDate = new Date(booking.fromDate)
const departureDate = new Date(booking.toDate) const departureDate = new Date(booking.toDate)
@@ -205,7 +204,7 @@ export function getTracking(
// @ts-expect-error - redemption object doesn't exist error // @ts-expect-error - redemption object doesn't exist error
rooms.find((room) => "redemption" in room.roomRate)?.roomRate.redemption rooms.find((room) => "redemption" in room.roomRate)?.roomRate.redemption
.localPrice.pointsPerStay ?? "n/a", .localPrice.pointsPerStay ?? "n/a",
searchTerm, searchTerm: hotel.name,
searchType: "hotel", searchType: "hotel",
specialRoomType: rooms specialRoomType: rooms
.map((room) => getSpecialRoomType(room.packages)) .map((room) => getSpecialRoomType(room.packages))

View File

@@ -7,6 +7,7 @@ import { useIntl } from "react-intl"
import { useSessionId } from "@scandic-hotels/common/hooks/useSessionId" import { useSessionId } from "@scandic-hotels/common/hooks/useSessionId"
import { toast } from "@scandic-hotels/design-system/Toast" import { toast } from "@scandic-hotels/design-system/Toast"
import { trackNoAvailability } from "@scandic-hotels/tracking/NoAvailabilityTracking" import { trackNoAvailability } from "@scandic-hotels/tracking/NoAvailabilityTracking"
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode" import { BookingErrorCodeEnum } from "@scandic-hotels/trpc/enums/bookingErrorCode"
import useLang from "../../hooks/useLang" import useLang from "../../hooks/useLang"
@@ -16,9 +17,13 @@ import type { SelectRateBooking } from "../../types/components/selectRate/select
type AvailabilityErrorProps = { type AvailabilityErrorProps = {
booking: SelectRateBooking booking: SelectRateBooking
hotelName: string
} }
export default function AvailabilityError({ booking }: AvailabilityErrorProps) { export default function AvailabilityError({
booking,
hotelName,
}: AvailabilityErrorProps) {
const intl = useIntl() const intl = useIntl()
const pathname = usePathname() const pathname = usePathname()
const searchParams = useSearchParams() const searchParams = useSearchParams()
@@ -53,13 +58,14 @@ export default function AvailabilityError({ booking }: AvailabilityErrorProps) {
trackNoAvailability({ trackNoAvailability({
specialRoomType, specialRoomType,
searchTerm: hotelId, searchTerm: hotelName,
lang, lang,
fromDate, fromDate,
toDate, toDate,
noOfRooms: rooms.length, noOfRooms: rooms.length,
searchType, searchType: "hotel",
hotelId, hotelId,
rewardNight: searchType === SEARCH_TYPE_REDEMPTION ? "yes" : "no",
bookingCode, bookingCode,
pageId: "select-rate", pageId: "select-rate",
pageName: "hotelreservation|select-rate", pageName: "hotelreservation|select-rate",
@@ -70,11 +76,12 @@ export default function AvailabilityError({ booking }: AvailabilityErrorProps) {
}) })
}, [ }, [
rooms, rooms,
hotelId, hotelName,
lang, lang,
fromDate, fromDate,
toDate, toDate,
searchType, searchType,
hotelId,
bookingCode, bookingCode,
sessionId, sessionId,
]) ])

View File

@@ -26,7 +26,7 @@ export function SelectRateTracking({ hotelData, booking }: TrackingProps) {
const { fromDate, toDate } = getValidDates(booking.fromDate, booking.toDate) const { fromDate, toDate } = getValidDates(booking.fromDate, booking.toDate)
const { rooms, searchType, bookingCode, city: paramCity } = booking const { rooms, searchType, bookingCode } = booking
const arrivalDate = fromDate.toDate() const arrivalDate = fromDate.toDate()
const departureDate = toDate.toDate() const departureDate = toDate.toDate()
@@ -47,7 +47,6 @@ export function SelectRateTracking({ hotelData, booking }: TrackingProps) {
hotelName: hotelData.hotel.name, hotelName: hotelData.hotel.name,
country: hotelData.hotel.address.country, country: hotelData.hotel.address.country,
hotelCity: hotelData.hotel.address.city, hotelCity: hotelData.hotel.address.city,
paramCity,
bookingCode, bookingCode,
isRedemption: searchType === SEARCH_TYPE_REDEMPTION, isRedemption: searchType === SEARCH_TYPE_REDEMPTION,
specialRoomType, specialRoomType,

View File

@@ -24,7 +24,6 @@ type SelectRateTrackingInput = {
hotelName: string hotelName: string
country: string | undefined country: string | undefined
hotelCity: string | undefined hotelCity: string | undefined
paramCity: string | undefined
bookingCode?: string bookingCode?: string
isRedemption?: boolean isRedemption?: boolean
specialRoomType?: string specialRoomType?: string
@@ -39,7 +38,6 @@ export function getSelectRateTracking({
hotelName, hotelName,
country, country,
hotelCity, hotelCity,
paramCity,
bookingCode, bookingCode,
isRedemption = false, isRedemption = false,
specialRoomType, specialRoomType,
@@ -80,7 +78,7 @@ export function getSelectRateTracking({
noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","), noOfChildren: childrenInRoom?.map((kids) => kids?.length ?? 0).join(","),
noOfRooms: rooms?.length ?? 0, noOfRooms: rooms?.length ?? 0,
region: hotelCity, region: hotelCity,
searchTerm: paramCity ?? hotelName, searchTerm: hotelName,
searchType: "hotel", searchType: "hotel",
bookingCode: bookingCode ?? "n/a", bookingCode: bookingCode ?? "n/a",
rewardNight: isRedemption ? "yes" : "no", rewardNight: isRedemption ? "yes" : "no",

View File

@@ -87,7 +87,7 @@ export async function SelectRate({
/> />
)} )}
<AvailabilityError booking={booking} /> <AvailabilityError booking={booking} hotelName={hotelData.hotel.name} />
</> </>
) )
} }

View File

@@ -41,6 +41,7 @@ type DetailsProviderProps = React.PropsWithChildren & {
searchParamsStr: string searchParamsStr: string
user: User | null user: User | null
vat: number vat: number
hotelName: string
roomCategories: RoomCategories roomCategories: RoomCategories
} }
@@ -53,6 +54,7 @@ export default function EnterDetailsProvider({
searchParamsStr, searchParamsStr,
user, user,
vat, vat,
hotelName,
roomCategories, roomCategories,
}: DetailsProviderProps) { }: DetailsProviderProps) {
// This state is needed to be able to use defaultValues for // This state is needed to be able to use defaultValues for
@@ -93,6 +95,7 @@ export default function EnterDetailsProvider({
isFlexRate: room.isFlexRate, isFlexRate: room.isFlexRate,
})), })),
vat, vat,
hotelName,
roomCategories, roomCategories,
} }

View File

@@ -98,7 +98,7 @@ export async function AlternativeHotelsMapPage({
departureDate, departureDate,
rooms: booking.rooms, rooms: booking.rooms,
hotelsResult: hotels.length, hotelsResult: hotels.length,
searchTerm: isAlternativeFor ? booking.hotelId : cityIdentifier, searchTerm: isAlternativeFor ? isAlternativeFor.name : cityIdentifier,
country: hotels?.[0]?.hotel.address.country, country: hotels?.[0]?.hotel.address.country,
hotelCity: hotels?.[0]?.hotel.address.city, hotelCity: hotels?.[0]?.hotel.address.city,
bookingCode: booking.bookingCode, bookingCode: booking.bookingCode,

View File

@@ -102,7 +102,7 @@ export async function AlternativeHotelsPage({
rooms: booking.rooms, rooms: booking.rooms,
hotelsResult: hotels?.length ?? 0, hotelsResult: hotels?.length ?? 0,
searchTerm: searchDetails.hotel searchTerm: searchDetails.hotel
? booking.hotelId ? searchDetails.hotel.name
: searchDetails.cityIdentifier, : searchDetails.cityIdentifier,
country: hotels?.[0]?.hotel.address.country, country: hotels?.[0]?.hotel.address.country,
hotelCity: hotels?.[0]?.hotel.address.city, hotelCity: hotels?.[0]?.hotel.address.city,

View File

@@ -128,6 +128,7 @@ export async function EnterDetailsPage({
rooms={rooms} rooms={rooms}
searchParamsStr={selectRoomParams.toString()} searchParamsStr={selectRoomParams.toString()}
user={user} user={user}
hotelName={hotel.name}
vat={hotel.vat} vat={hotel.vat}
roomCategories={hotelData.roomCategories} roomCategories={hotelData.roomCategories}
> >

View File

@@ -99,7 +99,7 @@ export async function SelectHotelMapPage({
departureDate, departureDate,
rooms: booking.rooms, rooms: booking.rooms,
hotelsResult: hotels.length, hotelsResult: hotels.length,
searchTerm: isAlternativeFor ? booking.hotelId : cityIdentifier, searchTerm: isAlternativeFor ? isAlternativeFor.name : cityIdentifier,
country: hotels?.[0]?.hotel.address.country, country: hotels?.[0]?.hotel.address.country,
hotelCity: hotels?.[0]?.hotel.address.city, hotelCity: hotels?.[0]?.hotel.address.city,
bookingCode: booking.bookingCode, bookingCode: booking.bookingCode,

View File

@@ -371,6 +371,7 @@ export function createDetailsStore(
searchParamString: searchParams, searchParamString: searchParams,
totalPrice: initialTotalPrice, totalPrice: initialTotalPrice,
vat: initialState.vat, vat: initialState.vat,
hotelName: initialState.hotelName,
defaultCurrency: initialTotalPrice.local.currency, defaultCurrency: initialTotalPrice.local.currency,
preSubmitCallbacks: {}, preSubmitCallbacks: {},

View File

@@ -87,6 +87,7 @@ export type InitialState = {
booking: DetailsBooking booking: DetailsBooking
rooms: InitialRoomData[] rooms: InitialRoomData[]
vat: number vat: number
hotelName: string
roomCategories: RoomCategories roomCategories: RoomCategories
} }
@@ -108,6 +109,7 @@ export interface DetailsState {
searchParamString: string searchParamString: string
totalPrice: Price totalPrice: Price
vat: number vat: number
hotelName: string
roomCategories: RoomCategories roomCategories: RoomCategories
defaultCurrency: CurrencyEnum defaultCurrency: CurrencyEnum
preSubmitCallbacks: Record<string, () => void> preSubmitCallbacks: Record<string, () => void>

View File

@@ -10,7 +10,6 @@ import {
type TrackingSDKHotelInfo, type TrackingSDKHotelInfo,
type TrackingSDKPageData, type TrackingSDKPageData,
} from "@scandic-hotels/tracking/types" } from "@scandic-hotels/tracking/types"
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
import { trackEvent } from "./base" import { trackEvent } from "./base"
import { createSDKPageObject } from "./pageview" import { createSDKPageObject } from "./pageview"
@@ -88,6 +87,7 @@ type TrackNoAvailabilityParams = {
searchType?: string searchType?: string
bookingCode?: string bookingCode?: string
searchTerm: string searchTerm: string
rewardNight: string
pageId: string pageId: string
pageName: string pageName: string
pageType: string pageType: string
@@ -107,6 +107,7 @@ export function trackNoAvailability({
searchType, searchType,
bookingCode, bookingCode,
searchTerm, searchTerm,
rewardNight,
pageId, pageId,
pageName, pageName,
pageType, pageType,
@@ -128,7 +129,7 @@ export function trackNoAvailability({
leadTime: differenceInCalendarDays(arrivalDate, new Date()), leadTime: differenceInCalendarDays(arrivalDate, new Date()),
noOfRooms, noOfRooms,
bookingCode: bookingCode ?? "n/a", bookingCode: bookingCode ?? "n/a",
rewardNight: searchType === SEARCH_TYPE_REDEMPTION ? "yes" : "no", rewardNight,
bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday", bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday",
duration: differenceInCalendarDays(departureDate, arrivalDate), duration: differenceInCalendarDays(departureDate, arrivalDate),
specialRoomType, specialRoomType,