Feat/SW-1472 destination tracking * feat(SW-1472): Added default tracking for destination overview page * feat(SW-1472): Added default tracking for destination country/city page * feat(SW-1472): moved tracking functions to different files for better overview * feat(SW-1472): added destination page tracking Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { trackEvent } from "./base"
|
|
|
|
import type { TrackingSDKData } from "@/types/components/tracking"
|
|
|
|
function convertSlashToPipe(url: string) {
|
|
const formattedUrl = url.startsWith("/") ? url.slice(1) : url
|
|
return formattedUrl.replaceAll("/", "|")
|
|
}
|
|
|
|
export function trackPageViewStart() {
|
|
trackEvent({
|
|
event: "pageViewStart",
|
|
})
|
|
}
|
|
|
|
export function trackPageView(data: any) {
|
|
if (typeof window !== "undefined" && window.adobeDataLayer) {
|
|
window.adobeDataLayer.push(data)
|
|
}
|
|
}
|
|
|
|
export function createSDKPageObject(
|
|
trackingData: TrackingSDKData
|
|
): TrackingSDKData {
|
|
let pageName = convertSlashToPipe(trackingData.pageName)
|
|
let siteSections = convertSlashToPipe(trackingData.siteSections)
|
|
|
|
if (trackingData.pathName.indexOf("/webview/") > -1) {
|
|
pageName = "webview|" + pageName
|
|
siteSections = "webview|" + siteSections
|
|
}
|
|
|
|
return {
|
|
...trackingData,
|
|
domain: typeof window !== "undefined" ? window.location.host : "",
|
|
pageName: pageName,
|
|
siteSections: siteSections,
|
|
}
|
|
}
|