Migrate to a monorepo setup - step 1 * Move web to subfolder /apps/scandic-web * Yarn + transitive deps - Move to yarn - design-system package removed for now since yarn doesn't support the parameter for token (ie project currently broken) - Add missing transitive dependencies as Yarn otherwise prevents these imports - VS Code doesn't pick up TS path aliases unless you open /apps/scandic-web instead of root (will be fixed with monorepo) * Pin framer-motion to temporarily fix typing issue https://github.com/adobe/react-spectrum/issues/7494 * Pin zod to avoid typ error There seems to have been a breaking change in the types returned by zod where error is now returned as undefined instead of missing in the type. We should just handle this but to avoid merge conflicts just pin the dependency for now. * Pin react-intl version Pin version of react-intl to avoid tiny type issue where formatMessage does not accept a generic any more. This will be fixed in a future commit, but to avoid merge conflicts just pin for now. * Pin typescript version Temporarily pin version as newer versions as stricter and results in a type error. Will be fixed in future commit after merge. * Setup workspaces * Add design-system as a monorepo package * Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN * Fix husky for monorepo setup * Update netlify.toml * Add lint script to root package.json * Add stub readme * Fix react-intl formatMessage types * Test netlify.toml in root * Remove root toml * Update netlify.toml publish path * Remove package-lock.json * Update build for branch/preview builds Approved-by: Linus Flood
200 lines
4.3 KiB
TypeScript
200 lines
4.3 KiB
TypeScript
import type { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
|
|
import type {
|
|
LowestRoomPriceEvent,
|
|
PaymentEvent,
|
|
PaymentFailEvent,
|
|
TrackingPosition,
|
|
TrackingSDKData,
|
|
} from "@/types/components/tracking"
|
|
|
|
export function trackClick(
|
|
name: string,
|
|
additionalParams?: Record<string, string>
|
|
) {
|
|
trackEvent({
|
|
event: "linkClick",
|
|
cta: {
|
|
...additionalParams,
|
|
name,
|
|
},
|
|
})
|
|
}
|
|
|
|
export function trackPageViewStart() {
|
|
trackEvent({
|
|
event: "pageViewStart",
|
|
})
|
|
}
|
|
|
|
export function trackLoginClick(position: TrackingPosition) {
|
|
const event = {
|
|
event: "loginStart",
|
|
login: {
|
|
position,
|
|
action: "login start",
|
|
ctaName: "login",
|
|
},
|
|
}
|
|
trackEvent(event)
|
|
}
|
|
|
|
export function trackSocialMediaClick(socialMediaName: string) {
|
|
const event = {
|
|
event: "social media",
|
|
social: {
|
|
socialIconClicked: socialMediaName,
|
|
},
|
|
}
|
|
trackEvent(event)
|
|
}
|
|
|
|
export function trackFooterClick(group: string, name: string) {
|
|
const event = {
|
|
event: "footer link",
|
|
footer: {
|
|
footerLinkClicked: `${group}:${name}`,
|
|
},
|
|
}
|
|
trackEvent(event)
|
|
}
|
|
|
|
export function trackHotelMapClick() {
|
|
const event = {
|
|
event: "map click",
|
|
map: {
|
|
action: "map click - open/explore mearby",
|
|
},
|
|
}
|
|
trackEvent(event)
|
|
}
|
|
|
|
export function trackAccordionClick(option: string) {
|
|
const event = {
|
|
event: "accordionClick",
|
|
accordion: {
|
|
action: "accordion open click",
|
|
option,
|
|
},
|
|
}
|
|
trackEvent(event)
|
|
}
|
|
|
|
export function trackHotelTabClick(name: string) {
|
|
trackEvent({
|
|
event: "linkClick",
|
|
link: {
|
|
action: "hotel menu click",
|
|
option: `hotel menu:${name}`,
|
|
},
|
|
})
|
|
}
|
|
|
|
export function trackUpdatePaymentMethod(hotelId: string, method: string) {
|
|
const paymentSelectionEvent = {
|
|
event: "paymentSelection",
|
|
hotelInfo: {
|
|
hotelId: hotelId,
|
|
},
|
|
cta: {
|
|
name: method,
|
|
},
|
|
}
|
|
trackEvent(paymentSelectionEvent)
|
|
}
|
|
|
|
export function trackOpenSidePeekEvent(
|
|
sidePeek: SidePeekEnum | null,
|
|
hotelId: string,
|
|
pathName: string,
|
|
roomTypeCode?: string | null
|
|
) {
|
|
const openSidePeekEvent = {
|
|
event: "openSidePeek",
|
|
hotelInfo: {
|
|
hotelId: hotelId,
|
|
},
|
|
cta: {
|
|
name: sidePeek,
|
|
roomTypeCode,
|
|
pathName,
|
|
},
|
|
}
|
|
trackEvent(openSidePeekEvent)
|
|
}
|
|
|
|
export function trackPaymentEvent(paymentEvent: PaymentEvent) {
|
|
const paymentAttempt = {
|
|
event: paymentEvent.event,
|
|
hotelInfo: {
|
|
hotelId: paymentEvent.hotelId,
|
|
},
|
|
paymentInfo: {
|
|
isSavedCard: paymentEvent.isSavedCreditCard,
|
|
status: paymentEvent.status,
|
|
type: paymentEvent.method,
|
|
smsEnable: paymentEvent.smsEnable,
|
|
errorMessage: isPaymentFailEvent(paymentEvent)
|
|
? paymentEvent.errorMessage
|
|
: undefined,
|
|
},
|
|
}
|
|
trackEvent(paymentAttempt)
|
|
}
|
|
|
|
export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
|
|
const lowestRoomPrice = {
|
|
event: "lowestRoomPrice",
|
|
hotelInfo: {
|
|
hotelId: event.hotelId,
|
|
arrivalDate: event.arrivalDate,
|
|
departureDate: event.departureDate,
|
|
},
|
|
viewItemInfo: {
|
|
lowestPrice: event.lowestPrice,
|
|
currency: event.currency,
|
|
},
|
|
}
|
|
trackEvent(lowestRoomPrice)
|
|
}
|
|
|
|
function trackEvent(data: any) {
|
|
if (typeof window !== "undefined" && window.adobeDataLayer) {
|
|
data = { ...data, siteVersion: "new-web" }
|
|
window.adobeDataLayer.push(data)
|
|
}
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|
|
|
|
function convertSlashToPipe(url: string) {
|
|
const formattedUrl = url.startsWith("/") ? url.slice(1) : url
|
|
return formattedUrl.replaceAll("/", "|")
|
|
}
|
|
|
|
function isPaymentFailEvent(event: PaymentEvent): event is PaymentFailEvent {
|
|
return "errorMessage" in event
|
|
}
|