Merged in fix/tracking-requests (pull request #1208)
Added siteversion to all events and fixed payment status * Added siteversion to all events and fixed payment status * Fixed bug Approved-by: Erik Tiekstra
This commit is contained in:
@@ -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, pushToDataLayer } from "@/utils/tracking"
|
import { createSDKPageObject, trackPageView } from "@/utils/tracking"
|
||||||
|
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import {
|
import {
|
||||||
@@ -156,7 +156,7 @@ export default function EnterDetailsTracking(props: Props) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (previousPathname.current !== pathName) {
|
if (previousPathname.current !== pathName) {
|
||||||
pushToDataLayer({
|
trackPageView({
|
||||||
event: "pageView",
|
event: "pageView",
|
||||||
pageInfo: pageObject,
|
pageInfo: pageObject,
|
||||||
userInfo: userTrackingData,
|
userInfo: userTrackingData,
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export default function PaymentCallback({
|
|||||||
trackPaymentEvent({
|
trackPaymentEvent({
|
||||||
event: "paymentCancel",
|
event: "paymentCancel",
|
||||||
hotelId: detailsStorage.booking.hotelId,
|
hotelId: detailsStorage.booking.hotelId,
|
||||||
|
status: "cancelled",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (status === "error") {
|
if (status === "error") {
|
||||||
@@ -45,6 +46,7 @@ export default function PaymentCallback({
|
|||||||
event: "paymentFail",
|
event: "paymentFail",
|
||||||
hotelId: detailsStorage.booking.hotelId,
|
hotelId: detailsStorage.booking.hotelId,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
status: "failed",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ export default function PaymentClient({
|
|||||||
isSavedCreditCard,
|
isSavedCreditCard,
|
||||||
smsEnable,
|
smsEnable,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
status: "failed",
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[intl, methods, savedCreditCards, hotelId]
|
[intl, methods, savedCreditCards, hotelId]
|
||||||
@@ -230,6 +231,7 @@ export default function PaymentClient({
|
|||||||
method: paymentMethod,
|
method: paymentMethod,
|
||||||
isSavedCreditCard: !!savedCreditCard,
|
isSavedCreditCard: !!savedCreditCard,
|
||||||
smsEnable: data.smsConfirmation,
|
smsEnable: data.smsConfirmation,
|
||||||
|
status: "attempt",
|
||||||
})
|
})
|
||||||
|
|
||||||
initiateBooking.mutate({
|
initiateBooking.mutate({
|
||||||
|
|||||||
@@ -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, pushToDataLayer } from "@/utils/tracking"
|
import { createSDKPageObject, trackPageView } from "@/utils/tracking"
|
||||||
|
|
||||||
import type { TrackingSDKProps } from "@/types/components/tracking"
|
import type { TrackingSDKProps } from "@/types/components/tracking"
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ export default function RouterTransition({
|
|||||||
pageLoadTime: entry.duration / 1000,
|
pageLoadTime: entry.duration / 1000,
|
||||||
}
|
}
|
||||||
const pageObject = createSDKPageObject(trackingData)
|
const pageObject = createSDKPageObject(trackingData)
|
||||||
pushToDataLayer({
|
trackPageView({
|
||||||
event: "pageView",
|
event: "pageView",
|
||||||
pageInfo: pageObject,
|
pageInfo: pageObject,
|
||||||
userInfo: userData,
|
userInfo: userData,
|
||||||
@@ -115,7 +115,7 @@ export default function RouterTransition({
|
|||||||
}
|
}
|
||||||
const pageObject = createSDKPageObject(trackingData)
|
const pageObject = createSDKPageObject(trackingData)
|
||||||
if (previousPathname.current !== pathName) {
|
if (previousPathname.current !== pathName) {
|
||||||
pushToDataLayer({
|
trackPageView({
|
||||||
event: "pageView",
|
event: "pageView",
|
||||||
pageInfo: pageObject,
|
pageInfo: pageObject,
|
||||||
userInfo: userData,
|
userInfo: userData,
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ type BasePaymentEvent = {
|
|||||||
method?: string
|
method?: string
|
||||||
isSavedCreditCard?: boolean
|
isSavedCreditCard?: boolean
|
||||||
smsEnable?: boolean
|
smsEnable?: boolean
|
||||||
|
status: "attempt" | "cancelled" | "failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PaymentAttemptStartEvent = BasePaymentEvent
|
export type PaymentAttemptStartEvent = BasePaymentEvent
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export function trackClick(
|
|||||||
name: string,
|
name: string,
|
||||||
additionalParams?: Record<string, string>
|
additionalParams?: Record<string, string>
|
||||||
) {
|
) {
|
||||||
pushToDataLayer({
|
trackEvent({
|
||||||
event: "linkClick",
|
event: "linkClick",
|
||||||
cta: {
|
cta: {
|
||||||
...additionalParams,
|
...additionalParams,
|
||||||
@@ -21,7 +21,7 @@ export function trackClick(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function trackPageViewStart() {
|
export function trackPageViewStart() {
|
||||||
pushToDataLayer({
|
trackEvent({
|
||||||
event: "pageViewStart",
|
event: "pageViewStart",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ export function trackLoginClick(position: TrackingPosition) {
|
|||||||
ctaName: "login",
|
ctaName: "login",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(event)
|
trackEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackSocialMediaClick(socialMediaName: string) {
|
export function trackSocialMediaClick(socialMediaName: string) {
|
||||||
@@ -45,7 +45,7 @@ export function trackSocialMediaClick(socialMediaName: string) {
|
|||||||
socialIconClicked: socialMediaName,
|
socialIconClicked: socialMediaName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(event)
|
trackEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackFooterClick(group: string, name: string) {
|
export function trackFooterClick(group: string, name: string) {
|
||||||
@@ -55,7 +55,7 @@ export function trackFooterClick(group: string, name: string) {
|
|||||||
footerLinkClicked: `${group}:${name}`,
|
footerLinkClicked: `${group}:${name}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(event)
|
trackEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackHotelMapClick() {
|
export function trackHotelMapClick() {
|
||||||
@@ -65,7 +65,7 @@ export function trackHotelMapClick() {
|
|||||||
action: "map click - open/explore mearby",
|
action: "map click - open/explore mearby",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(event)
|
trackEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackAccordionClick(option: string) {
|
export function trackAccordionClick(option: string) {
|
||||||
@@ -76,11 +76,11 @@ export function trackAccordionClick(option: string) {
|
|||||||
option,
|
option,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(event)
|
trackEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackHotelTabClick(name: string) {
|
export function trackHotelTabClick(name: string) {
|
||||||
pushToDataLayer({
|
trackEvent({
|
||||||
event: "linkClick",
|
event: "linkClick",
|
||||||
link: {
|
link: {
|
||||||
action: "hotel menu click",
|
action: "hotel menu click",
|
||||||
@@ -99,7 +99,7 @@ export function trackUpdatePaymentMethod(hotelId: string, method: string) {
|
|||||||
name: method,
|
name: method,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(paymentSelectionEvent)
|
trackEvent(paymentSelectionEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackOpenSidePeekEvent(
|
export function trackOpenSidePeekEvent(
|
||||||
@@ -119,7 +119,7 @@ export function trackOpenSidePeekEvent(
|
|||||||
pathName,
|
pathName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(openSidePeekEvent)
|
trackEvent(openSidePeekEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackPaymentEvent(paymentEvent: PaymentEvent) {
|
export function trackPaymentEvent(paymentEvent: PaymentEvent) {
|
||||||
@@ -130,7 +130,7 @@ export function trackPaymentEvent(paymentEvent: PaymentEvent) {
|
|||||||
},
|
},
|
||||||
paymentInfo: {
|
paymentInfo: {
|
||||||
isSavedCreditCard: paymentEvent.isSavedCreditCard,
|
isSavedCreditCard: paymentEvent.isSavedCreditCard,
|
||||||
status: "attempt",
|
status: paymentEvent.status,
|
||||||
type: paymentEvent.method,
|
type: paymentEvent.method,
|
||||||
smsEnable: paymentEvent.smsEnable,
|
smsEnable: paymentEvent.smsEnable,
|
||||||
errorMessage: isPaymentFailEvent(paymentEvent)
|
errorMessage: isPaymentFailEvent(paymentEvent)
|
||||||
@@ -138,7 +138,7 @@ export function trackPaymentEvent(paymentEvent: PaymentEvent) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(paymentAttempt)
|
trackEvent(paymentAttempt)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
|
export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
|
||||||
@@ -154,10 +154,17 @@ export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
|
|||||||
currency: event.currency,
|
currency: event.currency,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
pushToDataLayer(lowestRoomPrice)
|
trackEvent(lowestRoomPrice)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function pushToDataLayer(data: any) {
|
function trackEvent(data: any) {
|
||||||
|
if (typeof window !== "undefined" && window.adobeDataLayer) {
|
||||||
|
data = { ...data, siteVersion: "new-web" }
|
||||||
|
window.adobeDataLayer.push(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function trackPageView(data: any) {
|
||||||
if (typeof window !== "undefined" && window.adobeDataLayer) {
|
if (typeof window !== "undefined" && window.adobeDataLayer) {
|
||||||
window.adobeDataLayer.push(data)
|
window.adobeDataLayer.push(data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user