Merged in feat/SW-1414-guarantee-enter-details-tracking (pull request #1744)
Feat/SW-1414 guarantee enter details tracking * feat(SW-1414): add tracking for gla enter details * feat(SW-1414): add tracking for gla * feat(SW-1414): add tracking for gla in enter details * feat(SW-1414): fix pr comments * feat(SW-1414): fix pr comment client only * feat(SW-1414): fix pr comments * feat(SW-1414): add tracking on load Approved-by: Christian Andolf
This commit is contained in:
@@ -8,8 +8,11 @@ import { detailsStorageName } from "@/stores/enter-details"
|
||||
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import { trackPaymentEvent } from "@/utils/tracking"
|
||||
import { trackEvent } from "@/utils/tracking/base"
|
||||
import { convertObjToSearchParams } from "@/utils/url"
|
||||
|
||||
import { clearGlaSessionStorage, readGlaFromSessionStorage } from "./helpers"
|
||||
|
||||
import type { PersistedState } from "@/types/stores/enter-details"
|
||||
|
||||
export default function HandleErrorCallback({
|
||||
@@ -35,21 +38,54 @@ export default function HandleErrorCallback({
|
||||
searchObject
|
||||
)
|
||||
|
||||
const lateArrivalGuarantee = readGlaFromSessionStorage()
|
||||
|
||||
if (status === PaymentCallbackStatusEnum.Cancel) {
|
||||
trackPaymentEvent({
|
||||
event: "paymentCancel",
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
status: "cancelled",
|
||||
})
|
||||
if (lateArrivalGuarantee) {
|
||||
trackEvent({
|
||||
event: "glaCardSaveCancelled",
|
||||
hotelInfo: {
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
lateArrivalGuarantee,
|
||||
guaranteedProduct: "room",
|
||||
},
|
||||
paymentInfo: {
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
status: "glacardsavecancelled",
|
||||
},
|
||||
})
|
||||
} else {
|
||||
trackPaymentEvent({
|
||||
event: "paymentCancel",
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
status: "cancelled",
|
||||
})
|
||||
}
|
||||
}
|
||||
if (status === PaymentCallbackStatusEnum.Error) {
|
||||
trackPaymentEvent({
|
||||
event: "paymentFail",
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
errorMessage,
|
||||
status: "failed",
|
||||
})
|
||||
if (lateArrivalGuarantee) {
|
||||
trackEvent({
|
||||
event: "glaCardSaveFailed",
|
||||
hotelInfo: {
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
lateArrivalGuarantee,
|
||||
guaranteedProduct: "room",
|
||||
},
|
||||
paymentInfo: {
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
status: "glacardsavefailed",
|
||||
},
|
||||
})
|
||||
} else {
|
||||
trackPaymentEvent({
|
||||
event: "paymentFail",
|
||||
hotelId: detailsStorage.booking.hotelId,
|
||||
errorMessage,
|
||||
status: "failed",
|
||||
})
|
||||
}
|
||||
}
|
||||
clearGlaSessionStorage()
|
||||
|
||||
if (searchParams.size > 0) {
|
||||
router.replace(`${returnUrl}?${searchParams.toString()}`)
|
||||
|
||||
@@ -7,7 +7,9 @@ import { BookingStatusEnum, MEMBERSHIP_FAILED_ERROR } from "@/constants/booking"
|
||||
|
||||
import LoadingSpinner from "@/components/LoadingSpinner"
|
||||
import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus"
|
||||
import { trackEvent } from "@/utils/tracking/base"
|
||||
|
||||
import { clearGlaSessionStorage, readGlaFromSessionStorage } from "./helpers"
|
||||
import TimeoutSpinner from "./TimeoutSpinner"
|
||||
|
||||
const validBookingStatuses = [
|
||||
@@ -48,6 +50,17 @@ export default function HandleSuccessCallback({
|
||||
bookingStatus.reservationStatus as BookingStatusEnum
|
||||
)
|
||||
) {
|
||||
const lateArrivalGuarantee = readGlaFromSessionStorage()
|
||||
if (lateArrivalGuarantee) {
|
||||
trackEvent({
|
||||
event: "guaranteeBookingSuccess",
|
||||
hotelInfo: {
|
||||
lateArrivalGuarantee,
|
||||
guaranteedProduct: "room",
|
||||
},
|
||||
})
|
||||
clearGlaSessionStorage()
|
||||
}
|
||||
// a successful booking can still have membership errors
|
||||
const membershipFailedError = bookingStatus.errors.find(
|
||||
(e) => e.errorCode === MEMBERSHIP_FAILED_ERROR
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import "client-only"
|
||||
|
||||
export const glaStorageName = "gla-storage"
|
||||
|
||||
export function readGlaFromSessionStorage(): string | null {
|
||||
try {
|
||||
return sessionStorage.getItem(glaStorageName)
|
||||
} catch (error) {
|
||||
console.error("Error reading from session storage:", error)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function writeGlaToSessionStorage(lateArrivalGuarantee: string) {
|
||||
try {
|
||||
sessionStorage.setItem(glaStorageName, lateArrivalGuarantee)
|
||||
} catch (error) {
|
||||
console.error("Error writing to session storage:", error)
|
||||
}
|
||||
}
|
||||
|
||||
export function clearGlaSessionStorage() {
|
||||
sessionStorage.removeItem(glaStorageName)
|
||||
}
|
||||
Reference in New Issue
Block a user