Merged in feat/adjust-tracking (pull request #43)

Feat/adjust tracking
This commit is contained in:
Arvid Norlin
2024-02-23 12:54:53 +00:00
committed by Michael Zetterberg
10 changed files with 16 additions and 47 deletions

View File

@@ -3,4 +3,5 @@ CMS_API_KEY=""
CMS_ENVIRONMENT="development" CMS_ENVIRONMENT="development"
CMS_URL="https://eu-graphql.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}" CMS_URL="https://eu-graphql.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}"
CMS_PREVIEW_URL="https://graphql-preview.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}"; CMS_PREVIEW_URL="https://graphql-preview.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}";
CMS_PREVIEW_TOKEN="" CMS_PREVIEW_TOKEN=""
ADOBE_SCRIPT_SRC="https://mocked-url.se/tracking-script.js"

View File

@@ -38,8 +38,6 @@ export default async function CurrentContentPage({
} }
const pageData = response.data.all_current_blocks_page.items[0] const pageData = response.data.all_current_blocks_page.items[0]
const trackingData = { const trackingData = {
pageName: pageData.title,
pageType: pageData.__typename,
publishedDate: pageData.system.updated_at, publishedDate: pageData.system.updated_at,
createdDate: pageData.system.created_at, createdDate: pageData.system.created_at,
pageId: pageData.system.uid, pageId: pageData.system.uid,

View File

@@ -63,6 +63,10 @@ export default function RootLayout({
src="/Static/dist/js/main-ng.js?336b801d6b38eff10884" src="/Static/dist/js/main-ng.js?336b801d6b38eff10884"
strategy="lazyOnload" strategy="lazyOnload"
/> */} /> */}
<Script
strategy="beforeInteractive"
id="ensure-datalayer"
>{`window.datalayer = window.datalayer || {}`}</Script>
<AdobeScript /> <AdobeScript />
</head> </head>
<body> <body>

View File

@@ -2,22 +2,6 @@ import { env } from "@/env/server"
import Script from "next/script" import Script from "next/script"
const scriptScrs = {
// TODO: decide on naming and environments (development vs. test vs. staging etc)
development: "",
test: "https://assets.adobedtm.com/c1bd08b1e4e7/d64a7c1f5f17/launch-84c70d82a50c-staging.min.js",
production:
"https://assets.adobedtm.com/c1bd08b1e4e7/d64a7c1f5f17/launch-e56085bbe998.min.js",
}
export default function AdobeScript() { export default function AdobeScript() {
return ( return env.ADOBE_SCRIPT_SRC ? <Script src={env.ADOBE_SCRIPT_SRC} /> : null
<>
<Script
strategy="beforeInteractive"
id="ensure-datalayer"
>{`window.datalayer = window.datalayer || {}`}</Script>
<Script src={scriptScrs[env.NODE_ENV]} />
</>
)
} }

View File

@@ -40,19 +40,19 @@ function createPageObject(trackingData: TrackingData) {
return sitesections return sitesections
} }
const sitesections = getSiteSections(segments) const sitesections = getSiteSections(segments)
const { host: domain, href: pageurl } = window.location const { host: domain, href: fullurl, origin } = window.location
const page_obj = { const page_obj = {
pagename: trackingData.pageName, pagename: segments.join('|'),
pagetype: trackingData.pageType, pagetype: 'contentpage',
pageurl, // is window.location.href viable? pageurl: origin + trackingData.pathName,
fullurl,
createDate: trackingData.createdDate, createDate: trackingData.createdDate,
publishDate: trackingData.publishedDate, publishDate: trackingData.publishedDate,
domain, // is window.location.host viable? domain,
errorcode: null, // handle errorcode: null, // handle
querystring: trackingData.queryString || "", querystring: trackingData.queryString || "",
pageid: trackingData.pageId, pageid: trackingData.pageId,
sessionid: "<unique identifier of session>", // base on what? // sessionid: "<unique identifier of session>", // base on what?
domainlanguage: lang, domainlanguage: lang,
hotelbrand: "scandic", hotelbrand: "scandic",
siteversion: "new-web", siteversion: "new-web",
@@ -70,15 +70,6 @@ export default function Tracking({ pageData }: TrackingProps) {
const pageObject = createPageObject(trackingData) const pageObject = createPageObject(trackingData)
window.datalayer.page = pageObject window.datalayer.page = pageObject
// NOTE: Is this irrelevant för drop 1?
// var user_obj = {
// loginstatus: "<if the user is logged in or not>",
// memberid: "<unique meeting package membership id for the user>",
// memberlevel: "<member level of user>",
// }
// datalayer.user = user_obj;
}, [pathName, queryString, pageData]) }, [pathName, queryString, pageData])
return null return null

2
env/server.ts vendored
View File

@@ -12,6 +12,7 @@ export const env = createEnv({
NODE_ENV: z.enum(["development", "test", "production"]), NODE_ENV: z.enum(["development", "test", "production"]),
PRINT_QUERY: z.boolean().default(false), PRINT_QUERY: z.boolean().default(false),
REVALIDATE_SECRET: z.string(), REVALIDATE_SECRET: z.string(),
ADOBE_SCRIPT_SRC: z.string().optional(),
}, },
emptyStringAsUndefined: true, emptyStringAsUndefined: true,
runtimeEnv: { runtimeEnv: {
@@ -24,5 +25,6 @@ export const env = createEnv({
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
PRINT_QUERY: process.env.PRINT_QUERY, PRINT_QUERY: process.env.PRINT_QUERY,
REVALIDATE_SECRET: process.env.REVALIDATE_SECRET, REVALIDATE_SECRET: process.env.REVALIDATE_SECRET,
ADOBE_SCRIPT_SRC: process.env.ADOBE_SCRIPT_SRC,
}, },
}) })

View File

@@ -10,7 +10,6 @@
query GetCurrentBlockPage($locale: String!, $url: String!) { query GetCurrentBlockPage($locale: String!, $url: String!) {
all_current_blocks_page(limit: 1, locale: $locale, where: { url: $url }) { all_current_blocks_page(limit: 1, locale: $locale, where: { url: $url }) {
items { items {
__typename
aside { aside {
__typename __typename
...ContactAside ...ContactAside

View File

@@ -3,8 +3,6 @@ export type TrackingProps = {
pageId: string pageId: string
createdDate: string createdDate: string
publishedDate: string publishedDate: string
pageName: string
pageType: string
} }
} }
@@ -12,8 +10,6 @@ export type TrackingData = {
pathName: string pathName: string
queryString: string queryString: string
pageId: string pageId: string
pageName: string
pageType: string
publishedDate: string publishedDate: string
createdDate: string createdDate: string
} }

View File

@@ -11,7 +11,6 @@ import type { AllRequestResponse } from "./utils/all"
import type { import type {
AsideTypenameEnum, AsideTypenameEnum,
Typename, Typename,
PagesTypenameEnum,
} from "./utils/typename" } from "./utils/typename"
export type Asides = export type Asides =
@@ -34,7 +33,6 @@ export type Breadcrumbs = {
} }
export type BlockPage = { export type BlockPage = {
__typename: PagesTypenameEnum.CurrentBlocksPage
aside: Asides[] aside: Asides[]
blocks: Blocks[] blocks: Blocks[]
breadcrumbs: Breadcrumbs breadcrumbs: Breadcrumbs

View File

@@ -11,10 +11,6 @@ export enum BlocksTypenameEnum {
CurrentBlocksPageBlocksText = "CurrentBlocksPageBlocksText", CurrentBlocksPageBlocksText = "CurrentBlocksPageBlocksText",
} }
export enum PagesTypenameEnum {
CurrentBlocksPage = "CurrentBlocksPage",
}
export type BlocksTypename = keyof typeof BlocksTypenameEnum export type BlocksTypename = keyof typeof BlocksTypenameEnum
export type Typename<T, K> = T & { export type Typename<T, K> = T & {