fix: improve typings
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
"use client"
|
||||
|
||||
import {
|
||||
SiteSectionObject,
|
||||
TrackingData,
|
||||
TrackingProps,
|
||||
WindowWithDataLayer,
|
||||
} from "@/types/components/tracking"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
|
||||
declare const window: WindowWithDataLayer
|
||||
|
||||
function createPageObject(trackingData: TrackingData) {
|
||||
const [lang, ...segments] = trackingData.pathName
|
||||
.split("/")
|
||||
.filter((v: string) => v)
|
||||
|
||||
function getSiteSections(segments: string[]) {
|
||||
const sitesections: { [key: string]: string } = {}
|
||||
function getSiteSections(segments: string[]): SiteSectionObject {
|
||||
/*
|
||||
Adobe expects the properties sitesection1 - sitessection6, hence the for-loop below
|
||||
The segments ['explore-scandic', 'wifi'] should result in:
|
||||
@@ -29,8 +26,10 @@ function createPageObject(trackingData: TrackingData) {
|
||||
sitesection6: "explore-scandic|wifi||||",
|
||||
}
|
||||
*/
|
||||
const sitesections = {} as SiteSectionObject
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const key = "sitesection" + (i + 1)
|
||||
const key = ("sitesection" + (i + 1)) as keyof SiteSectionObject
|
||||
|
||||
sitesections[key] = segments.slice(0, i + 1).join("|")
|
||||
if (i > 0 && !segments[i]) {
|
||||
sitesections[key] = sitesections[key].concat(
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
export type WindowWithDataLayer = Window & {
|
||||
datalayer: { [key: string]: any }
|
||||
}
|
||||
|
||||
export type TrackingProps = {
|
||||
pageData: {
|
||||
pageId: string
|
||||
@@ -21,3 +17,12 @@ export type TrackingData = {
|
||||
publishedDate: string
|
||||
createdDate: string
|
||||
}
|
||||
|
||||
export type SiteSectionObject = {
|
||||
sitesection1: string
|
||||
sitesection2: string
|
||||
sitesection3: string
|
||||
sitesection4: string
|
||||
sitesection5: string
|
||||
sitesection6: string
|
||||
}
|
||||
|
||||
3
types/window.d.ts
vendored
Normal file
3
types/window.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
interface Window {
|
||||
datalayer: { [key: string]: any }
|
||||
}
|
||||
Reference in New Issue
Block a user