More props to track in enter details
This commit is contained in:
@@ -4,30 +4,75 @@ import { usePathname } from "next/navigation"
|
||||
import { useEffect, useMemo } from "react"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { RoomConfiguration } from "@/server/routers/hotels/output"
|
||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||
import useTrackingStore from "@/stores/tracking"
|
||||
|
||||
import { createSDKPageObject } from "@/utils/tracking"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
TrackingSDKHotelInfo,
|
||||
TrackingSDKPageData,
|
||||
TrackingSDKUserData,
|
||||
} from "@/types/components/tracking"
|
||||
import { Packages } from "@/types/requests/packages"
|
||||
|
||||
type Props = {
|
||||
initialHotelsTrackingData: TrackingSDKHotelInfo
|
||||
userTrackingData: TrackingSDKUserData
|
||||
lang: Lang
|
||||
selectedRoom: RoomConfiguration
|
||||
cancellationRule: string
|
||||
}
|
||||
|
||||
export default function EnterDetailsTracking(props: Props) {
|
||||
const { initialHotelsTrackingData, userTrackingData, lang } = props
|
||||
const currentStep = useEnterDetailsStore((state) => state.currentStep)
|
||||
const {
|
||||
initialHotelsTrackingData,
|
||||
userTrackingData,
|
||||
lang,
|
||||
selectedRoom,
|
||||
cancellationRule,
|
||||
} = props
|
||||
|
||||
const {
|
||||
currentStep,
|
||||
bedType,
|
||||
breakfast,
|
||||
totalPrice,
|
||||
roomPrice,
|
||||
roomRate,
|
||||
packages,
|
||||
} = useEnterDetailsStore((state) => state)
|
||||
const { getPageLoadTime, hasRun } = useTrackingStore()
|
||||
const pathName = usePathname()
|
||||
|
||||
const getSpecialRoomType = (packages: Packages | null) => {
|
||||
if (!packages) {
|
||||
return ""
|
||||
}
|
||||
|
||||
const specialRoom = packages.find((p) =>
|
||||
[
|
||||
RoomPackageCodeEnum.PET_ROOM,
|
||||
RoomPackageCodeEnum.ALLERGY_ROOM,
|
||||
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
||||
].includes(p.code)
|
||||
)
|
||||
|
||||
switch (specialRoom?.code) {
|
||||
case RoomPackageCodeEnum.PET_ROOM:
|
||||
return "pet-friendly"
|
||||
case RoomPackageCodeEnum.ALLERGY_ROOM:
|
||||
return "allergy room"
|
||||
case RoomPackageCodeEnum.ACCESSIBILITY_ROOM:
|
||||
return "accessibility room"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
const pageObject = useMemo(() => {
|
||||
const pageTrackingData: TrackingSDKPageData = {
|
||||
pageId: currentStep,
|
||||
@@ -48,9 +93,34 @@ export default function EnterDetailsTracking(props: Props) {
|
||||
}, [currentStep, getPageLoadTime, lang, pathName])
|
||||
|
||||
const hotelDetailsData = useMemo(() => {
|
||||
const data: TrackingSDKHotelInfo = { ...initialHotelsTrackingData }
|
||||
const data: TrackingSDKHotelInfo = {
|
||||
...initialHotelsTrackingData,
|
||||
rateCode: roomRate.memberRate?.rateCode,
|
||||
rateCodeType: roomRate.memberRate?.rateType,
|
||||
rateCodeName: roomRate.memberRate?.rateCode,
|
||||
rateCodeCancellationRule: cancellationRule,
|
||||
revenueCurrencyCode: roomRate.memberRate?.requestedPrice?.currency,
|
||||
breakfastOption: breakfast ? "breakfast buffet" : "no breakfast",
|
||||
totalPrice: totalPrice.euro?.price,
|
||||
specialRoomType: getSpecialRoomType(packages),
|
||||
roomTypeName: selectedRoom.roomType,
|
||||
bedType: bedType?.description,
|
||||
roomTypeCode: bedType?.roomTypeCode,
|
||||
roomPrice: roomPrice?.euro?.price,
|
||||
}
|
||||
|
||||
return data
|
||||
}, [initialHotelsTrackingData])
|
||||
}, [
|
||||
initialHotelsTrackingData,
|
||||
selectedRoom,
|
||||
cancellationRule,
|
||||
bedType,
|
||||
roomPrice,
|
||||
totalPrice,
|
||||
roomRate,
|
||||
breakfast,
|
||||
packages,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasRun) {
|
||||
|
||||
@@ -277,6 +277,8 @@ export default async function StepPage({
|
||||
<EnterDetailsTracking
|
||||
initialHotelsTrackingData={initialHotelsTrackingData}
|
||||
userTrackingData={userTrackingData}
|
||||
selectedRoom={roomAvailability.selectedRoom}
|
||||
cancellationRule={roomAvailability.cancellationText}
|
||||
lang={lang}
|
||||
/>
|
||||
<TrackingSDK
|
||||
|
||||
Reference in New Issue
Block a user