This commit is contained in:
Linus Flood
2025-01-10 11:36:23 +01:00
parent d57e3db34b
commit 08d5405cf1
7 changed files with 43 additions and 17 deletions

View File

@@ -20,12 +20,17 @@ export default async function PaymentCallbackPage({
searchParams, searchParams,
}: PageArgs< }: PageArgs<
LangParams, LangParams,
{ status: "error" | "success" | "cancel"; confirmationNumber?: string } {
status: "error" | "success" | "cancel"
confirmationNumber?: string
hotel?: string
}
>) { >) {
console.log(`[payment-callback] callback started`) console.log(`[payment-callback] callback started`)
const lang = params.lang const lang = params.lang
const status = searchParams.status const status = searchParams.status
const confirmationNumber = searchParams.confirmationNumber const confirmationNumber = searchParams.confirmationNumber
const hotelId = searchParams.hotel
if (status === "success" && confirmationNumber) { if (status === "success" && confirmationNumber) {
const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}` const confirmationUrl = `${bookingConfirmation(lang)}?${BOOKING_CONFIRMATION_NUMBER}=${confirmationNumber}`
@@ -50,7 +55,7 @@ export default async function PaymentCallbackPage({
) )
trackPaymentEvent({ trackPaymentEvent({
event: "paymentFail", event: "paymentFail",
hotelId: searchObject.get("hotel"), hotelId,
errorMessage: errorMessage:
bookingStatus?.metadata?.errorMessage ?? bookingStatus?.metadata?.errorMessage ??
`No error message found for booking ${confirmationNumber}, status: ${status}`, `No error message found for booking ${confirmationNumber}, status: ${status}`,
@@ -63,14 +68,14 @@ export default async function PaymentCallbackPage({
searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString()) searchObject.set("errorCode", PaymentErrorCodeEnum.Cancelled.toString())
trackPaymentEvent({ trackPaymentEvent({
event: "paymentCancel", event: "paymentCancel",
hotelId: searchObject.get("hotel"), hotelId,
}) })
} }
if (status === "error") { if (status === "error") {
searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString()) searchObject.set("errorCode", PaymentErrorCodeEnum.Failed.toString())
trackPaymentEvent({ trackPaymentEvent({
event: "paymentFail", event: "paymentFail",
hotelId: searchObject.get("hotel"), hotelId,
errorMessage: `Failed to get booking status for ${confirmationNumber}, status: ${status}`, errorMessage: `Failed to get booking status for ${confirmationNumber}, status: ${status}`,
}) })
} }

View File

@@ -5,7 +5,7 @@ import { useEffect, useMemo, useRef } from "react"
import { useEnterDetailsStore } from "@/stores/enter-details" import { useEnterDetailsStore } from "@/stores/enter-details"
import { useSessionId } from "@/hooks/useSessionId" import { useSessionId } from "@/hooks/useSessionId"
import { createSDKPageObject } from "@/utils/tracking" import { createSDKPageObject, pushToDataLayer } from "@/utils/tracking"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter" import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import { import {
@@ -145,7 +145,7 @@ export default function EnterDetailsTracking(props: Props) {
} }
//if (previousPathname.current !== pathName) { //if (previousPathname.current !== pathName) {
window.adobeDataLayer.push({ pushToDataLayer({
event: "pageView", event: "pageView",
pageInfo: pageObject, pageInfo: pageObject,
userInfo: userTrackingData, userInfo: userTrackingData,

View File

@@ -169,8 +169,8 @@ export default function PaymentClient({
event: "paymentFail", event: "paymentFail",
hotelId: hotel, hotelId: hotel,
method: currentPaymentMethod, method: currentPaymentMethod,
isSavedCreditCard: isSavedCreditCard, isSavedCreditCard,
smsEnable: smsEnable, smsEnable,
errorMessage, errorMessage,
}) })
}, },
@@ -224,7 +224,7 @@ export default function PaymentClient({
event: "paymentAttemptStart", event: "paymentAttemptStart",
hotelId: hotel, hotelId: hotel,
method: paymentMethod, method: paymentMethod,
isSavedCreditCard: savedCreditCard ? true : false, isSavedCreditCard: !!savedCreditCard,
smsEnable: data.smsConfirmation, smsEnable: data.smsConfirmation,
}) })

View File

@@ -75,6 +75,8 @@ export function createQueryParamsForEnterDetails(
...bookingSearchParams, ...bookingSearchParams,
]) ])
searchParams.set(`hotel`, hotel)
rooms.forEach((item, index) => { rooms.forEach((item, index) => {
if (item?.adults) { if (item?.adults) {
searchParams.set(`room[${index}].adults`, item.adults.toString()) searchParams.set(`room[${index}].adults`, item.adults.toString())

View File

@@ -13,7 +13,7 @@ import useRouterTransitionStore from "@/stores/router-transition"
import useTrackingStore from "@/stores/tracking" import useTrackingStore from "@/stores/tracking"
import { useSessionId } from "@/hooks/useSessionId" import { useSessionId } from "@/hooks/useSessionId"
import { createSDKPageObject } from "@/utils/tracking" import { createSDKPageObject, pushToDataLayer } from "@/utils/tracking"
import type { TrackingSDKProps } from "@/types/components/tracking" import type { TrackingSDKProps } from "@/types/components/tracking"
@@ -57,7 +57,7 @@ export default function RouterTransition({
pageLoadTime: entry.duration / 1000, pageLoadTime: entry.duration / 1000,
} }
const pageObject = createSDKPageObject(trackingData) const pageObject = createSDKPageObject(trackingData)
window.adobeDataLayer.push({ pushToDataLayer({
event: "pageView", event: "pageView",
pageInfo: pageObject, pageInfo: pageObject,
userInfo: userData, userInfo: userData,
@@ -104,7 +104,7 @@ export default function RouterTransition({
!isTransitioning && !isTransitioning &&
status === TransitionStatusEnum.Done status === TransitionStatusEnum.Done
) { ) {
if (window.adobeDataLayer && hasRun && !hasRunInitial.current) { if (hasRun && !hasRunInitial.current) {
const trackingData = { const trackingData = {
...pageData, ...pageData,
sessionId, sessionId,
@@ -112,7 +112,7 @@ export default function RouterTransition({
pageLoadTime: getPageLoadTime(), pageLoadTime: getPageLoadTime(),
} }
const pageObject = createSDKPageObject(trackingData) const pageObject = createSDKPageObject(trackingData)
window.adobeDataLayer.push({ pushToDataLayer({
event: "pageView", event: "pageView",
pageInfo: pageObject, pageInfo: pageObject,
userInfo: userData, userInfo: userData,

View File

@@ -105,15 +105,27 @@ export type TrackingSDKData = TrackingSDKPageData & {
pathName: string pathName: string
} }
export type PaymentEvent = { type BasePaymentEvent = {
event: string event: string
hotelId: string | null hotelId: string | undefined
method?: string method?: string
isSavedCreditCard?: boolean isSavedCreditCard?: boolean
smsEnable?: boolean smsEnable?: boolean
}
export type PaymentAttemptStartEvent = BasePaymentEvent
export type PaymentCancelEvent = BasePaymentEvent
export type PaymentFailEvent = BasePaymentEvent & {
errorMessage?: string errorMessage?: string
} }
export type PaymentEvent =
| PaymentAttemptStartEvent
| PaymentCancelEvent
| PaymentFailEvent
// Old tracking setup types: // Old tracking setup types:
// TODO: Remove this when we delete "current site" // TODO: Remove this when we delete "current site"
export type TrackingProps = { export type TrackingProps = {

View File

@@ -1,5 +1,6 @@
import type { import type {
PaymentEvent, PaymentEvent,
PaymentFailEvent,
TrackingPosition, TrackingPosition,
TrackingSDKData, TrackingSDKData,
} from "@/types/components/tracking" } from "@/types/components/tracking"
@@ -75,13 +76,15 @@ export function trackPaymentEvent(paymentEvent: PaymentEvent) {
status: "attempt", status: "attempt",
type: paymentEvent.method, type: paymentEvent.method,
smsEnable: paymentEvent.smsEnable, smsEnable: paymentEvent.smsEnable,
errorMessage: paymentEvent.errorMessage, errorMessage: isPaymentFailEvent(paymentEvent)
? paymentEvent.errorMessage
: undefined,
}, },
} }
pushToDataLayer(paymentAttempt) pushToDataLayer(paymentAttempt)
} }
function pushToDataLayer(data: any) { export function pushToDataLayer(data: any) {
if (typeof window !== "undefined" && window.adobeDataLayer) { if (typeof window !== "undefined" && window.adobeDataLayer) {
window.adobeDataLayer.push(data) window.adobeDataLayer.push(data)
} }
@@ -110,3 +113,7 @@ function convertSlashToPipe(url: string) {
const formattedUrl = url.startsWith("/") ? url.slice(1) : url const formattedUrl = url.startsWith("/") ? url.slice(1) : url
return formattedUrl.replaceAll("/", "|") return formattedUrl.replaceAll("/", "|")
} }
function isPaymentFailEvent(event: PaymentEvent): event is PaymentFailEvent {
return "errorMessage" in event
}