diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/page.tsx b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/page.tsx index bd81ddfa7..a649e3f9f 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/page.tsx +++ b/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/page.tsx @@ -15,15 +15,13 @@ import Multiroom from "@/components/HotelReservation/EnterDetails/Room/Multiroom import RoomOne from "@/components/HotelReservation/EnterDetails/Room/One" import DesktopSummary from "@/components/HotelReservation/EnterDetails/Summary/Desktop" import MobileSummary from "@/components/HotelReservation/EnterDetails/Summary/Mobile" +import EnterDetailsTrackingWrapper from "@/components/HotelReservation/EnterDetails/Tracking" import Alert from "@/components/TempDesignSystem/Alert" -import TrackingSDK from "@/components/TrackingSDK" import { getIntl } from "@/i18n" import RoomProvider from "@/providers/Details/RoomProvider" import EnterDetailsProvider from "@/providers/EnterDetailsProvider" import { convertSearchParamsToObj } from "@/utils/url" -import { getTracking } from "./tracking" - import styles from "./page.module.css" import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" @@ -96,16 +94,6 @@ export default async function DetailsPage({ hotel.merchantInformationData.alternatePaymentOptions = [] } - const { hotelsTrackingData, pageTrackingData, ancillaries } = getTracking( - booking, - hotel, - rooms, - !!breakfastPackages.length, - searchParams.city, - !!user, - lang - ) - const intl = await getIntl() const firstRoom = rooms[0] @@ -170,10 +158,13 @@ export default async function DetailsPage({ - ) diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx new file mode 100644 index 000000000..5dcb94a2c --- /dev/null +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/index.tsx @@ -0,0 +1,54 @@ +"use client" + +import { useEnterDetailsStore } from "@/stores/enter-details" + +import TrackingSDK from "@/components/TrackingSDK" + +import { getTracking } from "./tracking" + +import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" +import type { Hotel } from "@/types/hotel" +import type { Room } from "@/types/providers/details/room" +import type { Lang } from "@/constants/languages" +import type { SelectHotelParams } from "@/utils/url" + +interface TrackingWrapperProps { + booking: SelectHotelParams + hotel: Hotel + rooms: Room[] + city: string | undefined + isMember: boolean + lang: Lang +} + +export default function EnterDetailsTrackingWrapper({ + booking, + hotel, + rooms, + city, + isMember, + lang, +}: TrackingWrapperProps) { + const { storedRooms, breakfastPackages } = useEnterDetailsStore((state) => ({ + storedRooms: state.rooms, + breakfastPackages: state.breakfastPackages, + })) + + const { hotelsTrackingData, pageTrackingData, ancillaries } = getTracking( + booking, + hotel, + rooms, + city, + isMember, + lang, + storedRooms, + breakfastPackages + ) + return ( + + ) +} diff --git a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/tracking.ts b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts similarity index 92% rename from apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/tracking.ts rename to apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts index 24661c301..e3ebe3533 100644 --- a/apps/scandic-web/app/[lang]/(live)/(public)/hotelreservation/(standard)/details/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Tracking/tracking.ts @@ -6,6 +6,7 @@ import { sumPackages } from "@/components/HotelReservation/utils" import { getSpecialRoomType } from "@/utils/specialRoomType" import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums" +import type { BreakfastPackages } from "@/types/components/hotelReservation/breakfast" import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter" import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate" import { @@ -17,6 +18,7 @@ import { import { CurrencyEnum } from "@/types/enums/currency" import type { Hotel } from "@/types/hotel" import type { Room } from "@/types/providers/details/room" +import type { RoomState } from "@/types/stores/enter-details" import type { PriceProduct, Product, @@ -28,13 +30,27 @@ export function getTracking( booking: SelectHotelParams, hotel: Hotel, rooms: Room[], - offersBreakfast: boolean, city: string | undefined, isMember: boolean, - lang: Lang + lang: Lang, + storedRooms: RoomState[], + breakfastPackages: BreakfastPackages ) { const arrivalDate = new Date(booking.fromDate) const departureDate = new Date(booking.toDate) + const shouldSkipBreakfastOption = + storedRooms.every((r) => r.room.breakfast === undefined) || + !breakfastPackages.length + + const breakfastOption = shouldSkipBreakfastOption + ? undefined + : storedRooms + .map((r) => { + if (r.room.breakfast === undefined) return "-" + if (!r.room.breakfast) return "no breakfast" + return r.room.breakfast.description + }) + .join("|") const pageTrackingData: TrackingSDKPageData = { channel: TrackingChannelEnum.hotelreservation, @@ -45,7 +61,6 @@ export function getTracking( siteSections: "hotelreservation|details", siteVersion: "new-web", } - const hotelsTrackingData: TrackingSDKHotelInfo = { ageOfChildren: booking.rooms .map( @@ -54,9 +69,8 @@ export function getTracking( .join("|"), analyticsRateCode: rooms.map((room) => room.rate).join("|"), arrivalDate: format(arrivalDate, "yyyy-MM-dd"), - // only include bedtype here if it is "preselected" meanining there is only 1 - bedType: rooms - .map((r) => (r?.bedTypes?.length === 1 ? r.bedTypes[0].description : "-")) + bedType: storedRooms + .map((r) => (r.room.bedType ? r.room.bedType.description : "-")) .join("|"), // Comma separated booking code values in "code,code,n/a" format for multiroom and "code" or "n/a" for singleroom // n/a is used whenever code is Not applicable as defined by Tracking team @@ -70,9 +84,7 @@ export function getTracking( .join(", ") : undefined, bookingTypeofDay: isWeekend(arrivalDate) ? "weekend" : "weekday", - breakfastOption: rooms - .map(() => (offersBreakfast ? "breakfast buffet" : "no breakfast")) - .join(","), + breakfastOption, childBedPreference: booking.rooms .map( (room) => @@ -140,6 +152,7 @@ export function getTracking( return "-" }) .join("|"), + rateCodeCancellationRule: rooms .map((room) => room.cancellationText.toLowerCase()) .join(","), @@ -179,7 +192,6 @@ export function getTracking( .map((room) => getSpecialRoomType(room.packages)) .join(","), } - const roomsWithPetRoom = rooms.filter(hasPetRoom) const ancillaries: TrackingSDKAncillaries = roomsWithPetRoom .slice(0, 1) // should only be one item @@ -205,7 +217,6 @@ export function getTracking( ancillaries, } } - function hasPublicPrice( roomRate: Product ): roomRate is PriceProduct & { public: NonNullable } { @@ -214,7 +225,6 @@ function hasPublicPrice( } return false } - function hasMemberPrice( roomRate: Product ): roomRate is PriceProduct & { member: NonNullable } { @@ -223,7 +233,6 @@ function hasMemberPrice( } return false } - function hasPetRoom( room: Room ): room is Room & { packages: NonNullable } { @@ -232,17 +241,14 @@ function hasPetRoom( } return room.packages.some((p) => p.code === RoomPackageCodeEnum.PET_ROOM) } - function calcTotalPrice(rooms: Room[], isMember: boolean) { const totalRoomPrice = calcTotalRoomPrice(rooms, isMember) const totalPackageSum = rooms.reduce((total, room) => { const packageSum = sumPackages(room.packages) return (total += packageSum.price ?? 0) }, 0) - return totalRoomPrice + totalPackageSum } - function calcTotalRoomPrice(rooms: Room[], isMember: boolean) { return rooms.reduce((total, room, idx) => { // When it comes special rates, only redemption has additional price and that should be added @@ -257,14 +263,12 @@ function calcTotalRoomPrice(rooms: Room[], isMember: boolean) { ) { return 0 } - const isMainRoom = idx === 0 if (hasMemberPrice(room.roomRate) && isMember && isMainRoom) { total += room.roomRate.member.localPrice.pricePerStay } else if (hasPublicPrice(room.roomRate)) { total += room.roomRate.public.localPrice.pricePerStay } - return total }, 0) }