Merged in feat/sw-3525-sas-member-type-in-tracking (pull request #2931)
feat(SW-3525): Set correct member type in tracking for partner-sas * Set correct member type in tracking for partner-sas Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -42,7 +42,7 @@ type LoggedInScandicUserData = TrackingSDKUserDataBase & {
|
||||
}
|
||||
|
||||
type LoggedInEurobonusUserData = TrackingSDKUserDataBase & {
|
||||
memberType: "eurobonus"
|
||||
memberType: "sas-eurobonus"
|
||||
}
|
||||
|
||||
type TrackingSDKUserDataBase = {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const useTrackingUserData = () => {
|
||||
const userData: TrackingSDKUserData | undefined = !isPending
|
||||
? isError || !data
|
||||
? ({ loginStatus: "Error" } as const)
|
||||
: { ...data, memberType: "scandic-friends" }
|
||||
: data
|
||||
: undefined
|
||||
|
||||
return { userData, isPending, isError }
|
||||
|
||||
@@ -29,6 +29,7 @@ export function createContext(opts: CreateContextOptions) {
|
||||
url: opts.url,
|
||||
webToken: opts.webToken,
|
||||
contentType: opts.contentType,
|
||||
app: opts.app,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,10 @@ export type TrackingUserData =
|
||||
membershipNumber?: string
|
||||
memberLevel?: MembershipLevel
|
||||
loginAction?: "login success"
|
||||
memberType: "scandic-friends" | "sas-eurobonus"
|
||||
}
|
||||
| {
|
||||
loginStatus: "Non-logged in"
|
||||
memberType: "scandic-friends" | "sas-eurobonus"
|
||||
}
|
||||
| { loginStatus: "Error" }
|
||||
|
||||
@@ -6,22 +6,38 @@ import { getFriendsMembership } from "../helpers"
|
||||
import { getVerifiedUser } from "../utils/getVerifiedUser"
|
||||
|
||||
import type { LoginType } from "@scandic-hotels/common/constants/loginType"
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
import type { TrackingUserData } from "../../types"
|
||||
|
||||
export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
||||
ctx,
|
||||
}) {
|
||||
if (ctx.app === "partner-sas") {
|
||||
return getSasEurobonusUserTrackingData(ctx.session)
|
||||
}
|
||||
|
||||
if (ctx.app === "scandic-web") {
|
||||
return getScandicFriendsUserTrackingData(ctx.session)
|
||||
}
|
||||
|
||||
return { loginStatus: "Error" } as const
|
||||
})
|
||||
|
||||
async function getScandicFriendsUserTrackingData(session: Session | null) {
|
||||
const userTrackingInfoCounter = createCounter("user", "userTrackingInfo")
|
||||
const metricsUserTrackingInfo = userTrackingInfoCounter.init()
|
||||
|
||||
metricsUserTrackingInfo.start()
|
||||
|
||||
const memberType = "scandic-friends" as const
|
||||
|
||||
const notLoggedInUserTrackingData: TrackingUserData = {
|
||||
loginStatus: "Non-logged in",
|
||||
memberType,
|
||||
}
|
||||
|
||||
if (!isValidSession(ctx.session)) {
|
||||
if (!isValidSession(session)) {
|
||||
metricsUserTrackingInfo.success({
|
||||
reason: "invalid session",
|
||||
data: notLoggedInUserTrackingData,
|
||||
@@ -30,7 +46,7 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
||||
}
|
||||
|
||||
try {
|
||||
const verifiedUserData = await getVerifiedUser({ session: ctx.session })
|
||||
const verifiedUserData = await getVerifiedUser({ session: session })
|
||||
|
||||
if (
|
||||
!verifiedUserData ||
|
||||
@@ -48,11 +64,12 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
||||
|
||||
const loggedInUserTrackingData: TrackingUserData = {
|
||||
loginStatus: "logged in",
|
||||
loginType: ctx.session.token.loginType as LoginType,
|
||||
loginType: session.token.loginType as LoginType,
|
||||
memberId: verifiedUserData.data.profileId,
|
||||
membershipNumber: membership?.membershipNumber,
|
||||
memberLevel: membership?.membershipLevel,
|
||||
loginAction: "login success",
|
||||
memberType,
|
||||
}
|
||||
|
||||
metricsUserTrackingInfo.success({
|
||||
@@ -65,4 +82,28 @@ export const userTrackingInfo = safeProtectedProcedure.query(async function ({
|
||||
metricsUserTrackingInfo.fail(error)
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function getSasEurobonusUserTrackingData(session: Session | null) {
|
||||
const notLoggedInUserTrackingData: TrackingUserData = {
|
||||
loginStatus: "Non-logged in",
|
||||
memberType: "sas-eurobonus",
|
||||
}
|
||||
|
||||
if (!isValidSession(session)) {
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
|
||||
try {
|
||||
const loggedInUserTrackingData: TrackingUserData = {
|
||||
loginStatus: "logged in",
|
||||
loginType: session.token.loginType,
|
||||
loginAction: "login success",
|
||||
memberType: "sas-eurobonus",
|
||||
}
|
||||
|
||||
return loggedInUserTrackingData
|
||||
} catch (_error) {
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user