feat: add tracking events for loyalty pages
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
GetLoyaltyPageRefs,
|
||||
GetTrackingLoyaltyPage,
|
||||
} from "@/lib/graphql/Query/LoyaltyPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
@@ -29,6 +30,10 @@ import {
|
||||
LoyaltyCardsGridEnum,
|
||||
SidebarTypenameEnum,
|
||||
} from "@/types/components/loyalty/enums"
|
||||
import {
|
||||
TrackingChannelEnum,
|
||||
TrackingSDKPageData,
|
||||
} from "@/types/components/tracking"
|
||||
|
||||
function makeImageVaultImage(image: any) {
|
||||
return image && !!Object.keys(image).length
|
||||
@@ -224,4 +229,26 @@ export const loyaltyPageQueryRouter = router({
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return validatedLoyaltyPage.data as LoyaltyPage
|
||||
}),
|
||||
tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
const response = await request<any>(GetTrackingLoyaltyPage, {
|
||||
locale: lang,
|
||||
uid,
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
const loyaltyTrackingData: TrackingSDKPageData = {
|
||||
pageId: response.data.loyalty_page.system.uid,
|
||||
lang: response.data.loyalty_page.system.locale,
|
||||
publishedDate: response.data.loyalty_page.system.published_at,
|
||||
createdDate: response.data.loyalty_page.system.created_at,
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
}
|
||||
|
||||
return loyaltyTrackingData
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user