Merged in feat/SW-3494-noOfNightsStayed (pull request #2832)
feat(SW-3494): removed properties that we dont need in the tracking * feat(SW-3494): removed properties that we dont need in the tracking * Fixed waiting on user response before tracking * Refactor and cleanup * Cleanup Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
|
||||
import { usePathname } from "next/navigation"
|
||||
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
|
||||
import useLang from "./hooks/useLang"
|
||||
import { useTrackHardNavigation } from "./useTrackHardNavigation"
|
||||
import { useTrackSoftNavigation } from "./useTrackSoftNavigation"
|
||||
|
||||
@@ -13,7 +10,6 @@ import type {
|
||||
TrackingSDKHotelInfo,
|
||||
TrackingSDKPageData,
|
||||
TrackingSDKPaymentInfo,
|
||||
TrackingSDKUserData,
|
||||
} from "./types"
|
||||
|
||||
export function TrackingSDK({
|
||||
@@ -28,31 +24,20 @@ export function TrackingSDK({
|
||||
ancillaries?: TrackingSDKAncillaries
|
||||
}) {
|
||||
const pathName = usePathname()
|
||||
const lang = useLang()
|
||||
|
||||
const { data, isError } = trpc.user.userTrackingInfo.useQuery({
|
||||
lang,
|
||||
})
|
||||
|
||||
const userData: TrackingSDKUserData =
|
||||
!data || isError
|
||||
? ({ loginStatus: "Error" } as const)
|
||||
: { ...data, memberType: "scandic-friends" }
|
||||
|
||||
useTrackHardNavigation({
|
||||
pageData,
|
||||
hotelInfo,
|
||||
paymentInfo,
|
||||
ancillaries,
|
||||
userData,
|
||||
pathName,
|
||||
})
|
||||
|
||||
useTrackSoftNavigation({
|
||||
pageData,
|
||||
hotelInfo,
|
||||
paymentInfo,
|
||||
ancillaries,
|
||||
userData,
|
||||
pathName,
|
||||
})
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ type LoggedInScandicUserData = TrackingSDKUserDataBase & {
|
||||
memberId?: string
|
||||
membershipNumber?: string
|
||||
memberLevel?: MembershipLevel
|
||||
noOfNightsStayed?: number
|
||||
totalPointsAvailableToSpend?: number
|
||||
loginAction?: "login success"
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { logger } from "@scandic-hotels/common/logger"
|
||||
import { promiseWithTimeout } from "@scandic-hotels/common/utils/promiseWithTimeout"
|
||||
|
||||
import { createSDKPageObject, trackPageView } from "./pageview"
|
||||
import { useTrackingUserData } from "./useTrackingUserData"
|
||||
|
||||
import type {
|
||||
TrackingSDKAncillaries,
|
||||
@@ -21,7 +22,6 @@ type TrackingSDKProps = {
|
||||
hotelInfo?: TrackingSDKHotelInfo
|
||||
paymentInfo?: TrackingSDKPaymentInfo
|
||||
ancillaries?: TrackingSDKAncillaries
|
||||
userData: TrackingSDKUserData | undefined
|
||||
pathName: string
|
||||
}
|
||||
|
||||
@@ -31,12 +31,16 @@ export const useTrackHardNavigation = ({
|
||||
hotelInfo,
|
||||
paymentInfo,
|
||||
ancillaries,
|
||||
userData,
|
||||
pathName,
|
||||
}: TrackingSDKProps) => {
|
||||
const sessionId = useSessionId()
|
||||
const { userData, isPending } = useTrackingUserData()
|
||||
|
||||
useEffect(() => {
|
||||
if (isPending) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ import useRouterTransitionStore from "@scandic-hotels/common/stores/router-trans
|
||||
import useTrackingStore from "@scandic-hotels/common/stores/tracking"
|
||||
|
||||
import { createSDKPageObject, trackPageView } from "./pageview"
|
||||
import { useTrackingUserData } from "./useTrackingUserData"
|
||||
|
||||
import type {
|
||||
TrackingSDKAncillaries,
|
||||
TrackingSDKHotelInfo,
|
||||
TrackingSDKPageData,
|
||||
TrackingSDKPaymentInfo,
|
||||
TrackingSDKUserData,
|
||||
} from "./types"
|
||||
|
||||
type TrackingSDKProps = {
|
||||
@@ -21,7 +21,6 @@ type TrackingSDKProps = {
|
||||
hotelInfo?: TrackingSDKHotelInfo
|
||||
paymentInfo?: TrackingSDKPaymentInfo
|
||||
ancillaries?: TrackingSDKAncillaries
|
||||
userData: TrackingSDKUserData | undefined
|
||||
pathName: string
|
||||
}
|
||||
|
||||
@@ -38,7 +37,6 @@ export const useTrackSoftNavigation = ({
|
||||
hotelInfo,
|
||||
paymentInfo,
|
||||
ancillaries,
|
||||
userData,
|
||||
pathName,
|
||||
}: TrackingSDKProps) => {
|
||||
const [status, setStatus] = useState<TransitionStatus>(
|
||||
@@ -50,8 +48,13 @@ export const useTrackSoftNavigation = ({
|
||||
const { isTransitioning, stopRouterTransition } = useRouterTransitionStore()
|
||||
|
||||
const previousPathname = useRef<string | null>(null)
|
||||
const { userData, isPending } = useTrackingUserData()
|
||||
|
||||
useEffect(() => {
|
||||
if (isPending) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!userData) {
|
||||
return
|
||||
}
|
||||
|
||||
17
packages/tracking/lib/useTrackingUserData.ts
Normal file
17
packages/tracking/lib/useTrackingUserData.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
"use client"
|
||||
|
||||
import { trpc } from "@scandic-hotels/trpc/client"
|
||||
|
||||
import type { TrackingSDKUserData } from "./types"
|
||||
|
||||
export const useTrackingUserData = () => {
|
||||
const { data, isError, isPending } = trpc.user.userTrackingInfo.useQuery()
|
||||
|
||||
const userData: TrackingSDKUserData | undefined = !isPending
|
||||
? isError || !data
|
||||
? ({ loginStatus: "Error" } as const)
|
||||
: { ...data, memberType: "scandic-friends" }
|
||||
: undefined
|
||||
|
||||
return { userData, isPending, isError }
|
||||
}
|
||||
Reference in New Issue
Block a user