From 546679387febc9860e51e278a77a006f3a1ae356 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Thu, 11 Jul 2024 11:12:08 +0200 Subject: [PATCH] feat: add tracking to account pages --- .../(protected)/my-pages/[...path]/page.tsx | 5 +++ .../my-pages/profile/@profile/page.tsx | 2 +- .../my-pages/profile/edit/page.tsx | 11 +++++-- .../(protected)/my-pages/profile/page.tsx | 11 +++++-- lib/graphql/Query/AccountPage.graphql | 11 +++++++ .../contentstack/accountPage/output.ts | 14 ++++++++ .../routers/contentstack/accountPage/query.ts | 32 +++++++++++++++++++ .../contentstack/loyaltyPage/output.ts | 14 ++++++++ .../routers/contentstack/loyaltyPage/query.ts | 17 ++++++---- 9 files changed, 106 insertions(+), 11 deletions(-) diff --git a/app/[lang]/(live)/(protected)/my-pages/[...path]/page.tsx b/app/[lang]/(live)/(protected)/my-pages/[...path]/page.tsx index caca3de82..3d3bb20e2 100644 --- a/app/[lang]/(live)/(protected)/my-pages/[...path]/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/[...path]/page.tsx @@ -1,5 +1,6 @@ import { serverClient } from "@/lib/trpc/server" +import TrackingSDK from "@/components/Current/TrackingSDK" import Content from "@/components/MyPages/AccountPage/Content" import Title from "@/components/TempDesignSystem/Text/Title" import { getIntl } from "@/i18n" @@ -18,6 +19,9 @@ export default async function MyPages({ return null } + const accountPageTracking = + await serverClient().contentstack.accountPage.tracking() + return (
{accountPage.heading} @@ -26,6 +30,7 @@ export default async function MyPages({ ) : (

{formatMessage({ id: "No content published" })}

)} +
) } diff --git a/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx b/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx index 16b9e56ad..81ccf6cb8 100644 --- a/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx @@ -50,7 +50,7 @@ export default async function Profile({ params }: PageArgs) {
- {formatMessage({ id: "Date of birth" })} + {formatMessage({ id: "Date of Birth" })} {user.dateOfBirth}
diff --git a/app/[lang]/(live)/(protected)/my-pages/profile/edit/page.tsx b/app/[lang]/(live)/(protected)/my-pages/profile/edit/page.tsx index 496477ced..6cd9cf94d 100644 --- a/app/[lang]/(live)/(protected)/my-pages/profile/edit/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/profile/edit/page.tsx @@ -1,5 +1,12 @@ import "../profileLayout.css" -export default function EditProfilePage() { - return null +import { serverClient } from "@/lib/trpc/server" + +import TrackingSDK from "@/components/Current/TrackingSDK" + +export default async function EditProfilePage() { + const accountPageTracking = + await serverClient().contentstack.accountPage.tracking() + + return } diff --git a/app/[lang]/(live)/(protected)/my-pages/profile/page.tsx b/app/[lang]/(live)/(protected)/my-pages/profile/page.tsx index cc60f11d8..d548f8fc1 100644 --- a/app/[lang]/(live)/(protected)/my-pages/profile/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/profile/page.tsx @@ -1,5 +1,12 @@ import "./profileLayout.css" -export default function ProfilePage() { - return null +import { serverClient } from "@/lib/trpc/server" + +import TrackingSDK from "@/components/Current/TrackingSDK" + +export default async function ProfilePage() { + const accountPageTracking = + await serverClient().contentstack.accountPage.tracking() + + return } diff --git a/lib/graphql/Query/AccountPage.graphql b/lib/graphql/Query/AccountPage.graphql index f74ffae5e..1df21d608 100644 --- a/lib/graphql/Query/AccountPage.graphql +++ b/lib/graphql/Query/AccountPage.graphql @@ -99,3 +99,14 @@ query GetFiNoSvUrlsAccountPage($uid: String!) { } } } + +query GetTrackingAccountPage($locale: String!, $uid: String!) { + account_page(locale: $locale, uid: $uid) { + system { + locale + created_at + uid + updated_at + } + } +} diff --git a/server/routers/contentstack/accountPage/output.ts b/server/routers/contentstack/accountPage/output.ts index c3c86676a..6545039cf 100644 --- a/server/routers/contentstack/accountPage/output.ts +++ b/server/routers/contentstack/accountPage/output.ts @@ -189,3 +189,17 @@ export const validateAccountPageRefsSchema = z.object({ export type AccountPageRefsDataRaw = z.infer< typeof validateAccountPageRefsSchema > + +//Tracking +const validateAccountTrackingData = z.object({ + account_page: z.object({ + system: z.object({ + uid: z.string(), + locale: z.string(), + updated_at: z.string(), + created_at: z.string(), + }), + }), +}) + +export type AccountPageTackingData = z.infer diff --git a/server/routers/contentstack/accountPage/query.ts b/server/routers/contentstack/accountPage/query.ts index 9098604b7..0b445e435 100644 --- a/server/routers/contentstack/accountPage/query.ts +++ b/server/routers/contentstack/accountPage/query.ts @@ -1,6 +1,8 @@ +import { Lang } from "@/constants/languages" import { GetAccountPage, GetAccountPageRefs, + GetTrackingAccountPage, } from "@/lib/graphql/Query/AccountPage.graphql" import { request } from "@/lib/graphql/request" import { notFound } from "@/server/errors/trpc" @@ -17,12 +19,17 @@ import { type AccountPage, AccountPageDataRaw, AccountPageRefsDataRaw, + AccountPageTackingData, validateAccountPageRefsSchema, validateAccountPageSchema, } from "./output" import { getConnections } from "./utils" import { ContentEntries } from "@/types/components/myPages/myPage/enums" +import { + TrackingChannelEnum, + TrackingSDKPageData, +} from "@/types/components/tracking" import { Embeds } from "@/types/requests/embeds" import { Edges } from "@/types/requests/utils/edges" import { RTEDocument } from "@/types/rte/node" @@ -131,4 +138,29 @@ export const accountPageQueryRouter = router({ return accountPage }), + tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => { + const { lang, uid } = ctx + + const response = await request( + GetTrackingAccountPage, + { + locale: lang, + uid, + } + ) + + if (!response.data) { + throw notFound(response) + } + + const accountTrackingData: TrackingSDKPageData = { + pageId: response.data.account_page.system.uid, + lang: response.data.account_page.system.locale as Lang, + publishedDate: response.data.account_page.system.updated_at, + createdDate: response.data.account_page.system.created_at, + channel: TrackingChannelEnum["scandic-friends"], + } + + return accountTrackingData + }), }) diff --git a/server/routers/contentstack/loyaltyPage/output.ts b/server/routers/contentstack/loyaltyPage/output.ts index 8c1374ff2..043ec508d 100644 --- a/server/routers/contentstack/loyaltyPage/output.ts +++ b/server/routers/contentstack/loyaltyPage/output.ts @@ -417,3 +417,17 @@ export const validateLoyaltyPageRefsSchema = z.object({ export type LoyaltyPageRefsDataRaw = z.infer< typeof validateLoyaltyPageRefsSchema > + +//Tracking +const validateLoyaltyTrackingData = z.object({ + loyalty_page: z.object({ + system: z.object({ + uid: z.string(), + locale: z.string(), + updated_at: z.string(), + created_at: z.string(), + }), + }), +}) + +export type LoyaltyPageTackingData = z.infer diff --git a/server/routers/contentstack/loyaltyPage/query.ts b/server/routers/contentstack/loyaltyPage/query.ts index 096fb0492..42ee17794 100644 --- a/server/routers/contentstack/loyaltyPage/query.ts +++ b/server/routers/contentstack/loyaltyPage/query.ts @@ -1,3 +1,4 @@ +import { Lang } from "@/constants/languages" import { GetLoyaltyPage, GetLoyaltyPageRefs, @@ -19,6 +20,7 @@ import { removeEmptyObjects } from "../../utils" import { LoyaltyPage, type LoyaltyPageRefsDataRaw, + LoyaltyPageTackingData, validateLoyaltyPageRefsSchema, validateLoyaltyPageSchema, } from "./output" @@ -232,10 +234,13 @@ export const loyaltyPageQueryRouter = router({ tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => { const { lang, uid } = ctx - const response = await request(GetTrackingLoyaltyPage, { - locale: lang, - uid, - }) + const response = await request( + GetTrackingLoyaltyPage, + { + locale: lang, + uid, + } + ) if (!response.data) { throw notFound(response) @@ -243,8 +248,8 @@ export const loyaltyPageQueryRouter = router({ 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, + lang: response.data.loyalty_page.system.locale as Lang, + publishedDate: response.data.loyalty_page.system.updated_at, createdDate: response.data.loyalty_page.system.created_at, channel: TrackingChannelEnum["scandic-friends"], }