Merged in feat/SW-1472-destination-tracking (pull request #1474)
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
This commit is contained in:
39
apps/scandic-web/utils/tracking/pageview.ts
Normal file
39
apps/scandic-web/utils/tracking/pageview.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user