From e4a66499e5cb65ea1c97ad6286933988e015a8e6 Mon Sep 17 00:00:00 2001 From: Anton Gunnarsson Date: Wed, 27 Aug 2025 12:29:46 +0000 Subject: [PATCH] Merged in feat/sw-3322-move-base-tracking-to-common (pull request #2713) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(SW-3322): Move base tracking to common package * Move base tracking to common package * Update lock file Approved-by: Joakim Jäderberg --- .../Payment/PaymentCallback/HandleErrorCallback.tsx | 2 +- .../EnterDetails/Payment/PaymentCallback/tracking.ts | 2 +- .../EnterDetails/Payment/PaymentClient.tsx | 2 +- .../HotelReservation/MyStay/TrackGuarantee.tsx | 3 ++- .../SelectHotel/Filters/HotelFilter/index.tsx | 3 ++- .../HotelReservation/SelectHotel/HotelSorter/index.tsx | 3 +-- .../SelectHotelMap/SelectHotelMapContent/index.tsx | 2 +- apps/scandic-web/components/TrackingSDK/hooks.ts | 2 +- apps/scandic-web/hooks/booking/useGuaranteeBooking.ts | 2 +- apps/scandic-web/stores/enter-details/helpers.ts | 2 +- apps/scandic-web/utils/tracking/booking.ts | 2 +- apps/scandic-web/utils/tracking/componentEvents.ts | 2 +- apps/scandic-web/utils/tracking/destinationPage.ts | 2 +- apps/scandic-web/utils/tracking/form.ts | 2 +- apps/scandic-web/utils/tracking/hotelPage.ts | 2 +- apps/scandic-web/utils/tracking/index.ts | 2 +- apps/scandic-web/utils/tracking/myStay.ts | 3 +-- apps/scandic-web/utils/tracking/navigation.ts | 2 +- apps/scandic-web/utils/tracking/pageview.ts | 2 +- apps/scandic-web/utils/tracking/payment.ts | 2 +- packages/common/global.d.ts | 10 ++++++++++ .../common}/hooks/useSessionId.ts | 0 packages/common/package.json | 2 ++ .../utils => packages/common}/tracking/base.ts | 5 ++--- yarn.lock | 1 + 25 files changed, 37 insertions(+), 25 deletions(-) rename {apps/scandic-web => packages/common}/hooks/useSessionId.ts (100%) rename {apps/scandic-web/utils => packages/common}/tracking/base.ts (86%) diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback.tsx index 9219e40a1..6d082a9f7 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/HandleErrorCallback.tsx @@ -4,13 +4,13 @@ import { useRouter } from "next/navigation" import { useEffect } from "react" import { serializeBookingSearchParams } from "@scandic-hotels/booking-flow/utils/url" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import { PaymentCallbackStatusEnum } from "@/constants/booking" import { detailsStorageName } from "@/stores/enter-details" import LoadingSpinner from "@/components/LoadingSpinner" import { trackPaymentEvent } from "@/utils/tracking" -import { trackEvent } from "@/utils/tracking/base" import { clearPaymentInfoSessionStorage, diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/tracking.ts b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/tracking.ts index 16e7409ad..a67bff5c2 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/tracking.ts +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentCallback/tracking.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "@/utils/tracking/base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import { clearGlaSessionStorage, readGlaFromSessionStorage } from "./helpers" diff --git a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx index 87b9d29e3..1c4e1f37c 100644 --- a/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx +++ b/apps/scandic-web/components/HotelReservation/EnterDetails/Payment/PaymentClient.tsx @@ -15,6 +15,7 @@ import { } from "@scandic-hotels/common/constants/routes/hotelReservation" import useStickyPosition from "@scandic-hotels/common/hooks/useStickyPosition" import { logger } from "@scandic-hotels/common/logger" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import Body from "@scandic-hotels/design-system/Body" import { Button } from "@scandic-hotels/design-system/Button" import Checkbox from "@scandic-hotels/design-system/Form/Checkbox" @@ -35,7 +36,6 @@ import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus" import useLang from "@/hooks/useLang" import { formatPhoneNumber } from "@/utils/phone" import { trackPaymentEvent } from "@/utils/tracking" -import { trackEvent } from "@/utils/tracking/base" import { trackGlaSaveCardAttempt } from "@/utils/tracking/myStay" import ConfirmBooking, { ConfirmBookingRedemption } from "../Confirm" diff --git a/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx b/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx index 8e5949330..f4f658f87 100644 --- a/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx +++ b/apps/scandic-web/components/HotelReservation/MyStay/TrackGuarantee.tsx @@ -3,6 +3,8 @@ import { useRouter } from "next/navigation" import { useEffect } from "react" +import { trackEvent } from "@scandic-hotels/common/tracking/base" + import { PaymentCallbackStatusEnum } from "@/constants/booking" import { @@ -11,7 +13,6 @@ import { } from "@/components/HotelReservation/EnterDetails/Payment/PaymentCallback/helpers" import { getAncillarySessionData } from "@/components/HotelReservation/MyStay/utils/ancillaries" import LoadingSpinner from "@/components/LoadingSpinner" -import { trackEvent } from "@/utils/tracking/base" import { buildAncillariesTracking, buildBreakfastTracking, diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/HotelFilter/index.tsx b/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/HotelFilter/index.tsx index 83b7efa21..4c7a55a2a 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/HotelFilter/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/Filters/HotelFilter/index.tsx @@ -3,10 +3,11 @@ import { usePathname, useSearchParams } from "next/navigation" import { useCallback, useEffect } from "react" +import { trackEvent } from "@scandic-hotels/common/tracking/base" + import { useHotelFilterStore } from "@/stores/hotel-filters" import useInitializeFiltersFromUrl from "@/hooks/useInitializeFiltersFromUrl" -import { trackEvent } from "@/utils/tracking/base" import FilterContent from "../FilterContent" diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/HotelSorter/index.tsx b/apps/scandic-web/components/HotelReservation/SelectHotel/HotelSorter/index.tsx index 785d87427..c3c19d5ad 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/HotelSorter/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/HotelSorter/index.tsx @@ -4,10 +4,9 @@ import { usePathname, useSearchParams } from "next/navigation" import { useCallback } from "react" import { useIntl } from "react-intl" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import DeprecatedSelect from "@scandic-hotels/design-system/DeprecatedSelect" -import { trackEvent } from "@/utils/tracking/base" - import { type HotelSorterProps, type SortItem, diff --git a/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx b/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx index c1a332820..b12e62ee3 100644 --- a/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx +++ b/apps/scandic-web/components/HotelReservation/SelectHotel/SelectHotelMap/SelectHotelMapContent/index.tsx @@ -15,6 +15,7 @@ import { selectHotel, } from "@scandic-hotels/common/constants/routes/hotelReservation" import { useScrollToTop } from "@scandic-hotels/common/hooks/useScrollToTop" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import { debounce } from "@scandic-hotels/common/utils/debounce" import { BackToTopButton } from "@scandic-hotels/design-system/BackToTopButton" import { Button } from "@scandic-hotels/design-system/Button" @@ -30,7 +31,6 @@ import { RoomCardSkeleton } from "@/components/HotelReservation/RoomCardSkeleton import { useIsUserLoggedIn } from "@/hooks/useIsUserLoggedIn" import useLang from "@/hooks/useLang" import { mapApiImagesToGalleryImages } from "@/utils/imageGallery" -import { trackEvent } from "@/utils/tracking/base" import FilterAndSortModal from "../../Filters/FilterAndSortModal" import HotelListing from "../HotelListing" diff --git a/apps/scandic-web/components/TrackingSDK/hooks.ts b/apps/scandic-web/components/TrackingSDK/hooks.ts index 521e6fa8a..d9c986afc 100644 --- a/apps/scandic-web/components/TrackingSDK/hooks.ts +++ b/apps/scandic-web/components/TrackingSDK/hooks.ts @@ -15,6 +15,7 @@ import { type UseFromSubscribe, } from "react-hook-form" +import { useSessionId } from "@scandic-hotels/common/hooks/useSessionId" import { logger } from "@scandic-hotels/common/logger" import { trpc } from "@scandic-hotels/trpc/client" @@ -22,7 +23,6 @@ import useRouterTransitionStore from "@/stores/router-transition" import useTrackingStore from "@/stores/tracking" import useLang from "@/hooks/useLang" -import { useSessionId } from "@/hooks/useSessionId" import { promiseWithTimeout } from "@/utils/promiseWithTimeout" import { createSDKPageObject, trackPageView } from "@/utils/tracking" import { diff --git a/apps/scandic-web/hooks/booking/useGuaranteeBooking.ts b/apps/scandic-web/hooks/booking/useGuaranteeBooking.ts index 42549ee21..365aade76 100644 --- a/apps/scandic-web/hooks/booking/useGuaranteeBooking.ts +++ b/apps/scandic-web/hooks/booking/useGuaranteeBooking.ts @@ -2,12 +2,12 @@ import { useRouter } from "next/navigation" import { useCallback, useEffect, useState } from "react" import { useIntl } from "react-intl" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import { trpc } from "@scandic-hotels/trpc/client" import { BookingStatusEnum } from "@scandic-hotels/trpc/enums/bookingStatus" import { toast } from "@/components/TempDesignSystem/Toasts" import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus" -import { trackEvent } from "@/utils/tracking/base" const maxRetries = 15 const retryInterval = 2000 diff --git a/apps/scandic-web/stores/enter-details/helpers.ts b/apps/scandic-web/stores/enter-details/helpers.ts index 835fb82f6..a551c27e0 100644 --- a/apps/scandic-web/stores/enter-details/helpers.ts +++ b/apps/scandic-web/stores/enter-details/helpers.ts @@ -2,8 +2,8 @@ import isEqual from "fast-deep-equal" import { parsePhoneNumberFromString } from "libphonenumber-js" import { CurrencyEnum } from "@scandic-hotels/common/constants/currency" -import { logger } from "@scandic-hotels/common/logger" import { RateTypeEnum } from "@scandic-hotels/common/constants/rateType" +import { logger } from "@scandic-hotels/common/logger" import { sumPackages, diff --git a/apps/scandic-web/utils/tracking/booking.ts b/apps/scandic-web/utils/tracking/booking.ts index a96a6b889..94e6e83bf 100644 --- a/apps/scandic-web/utils/tracking/booking.ts +++ b/apps/scandic-web/utils/tracking/booking.ts @@ -1,6 +1,6 @@ "use client" -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import type { BreakfastPackages } from "@/types/components/hotelReservation/breakfast" import type { LowestRoomPriceEvent } from "@/types/components/tracking" diff --git a/apps/scandic-web/utils/tracking/componentEvents.ts b/apps/scandic-web/utils/tracking/componentEvents.ts index e239533ce..b1cf0b626 100644 --- a/apps/scandic-web/utils/tracking/componentEvents.ts +++ b/apps/scandic-web/utils/tracking/componentEvents.ts @@ -1,5 +1,5 @@ "use client" -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" export function trackAccordionClick(option: string) { trackEvent({ diff --git a/apps/scandic-web/utils/tracking/destinationPage.ts b/apps/scandic-web/utils/tracking/destinationPage.ts index bff8f29cf..452d4d3f7 100644 --- a/apps/scandic-web/utils/tracking/destinationPage.ts +++ b/apps/scandic-web/utils/tracking/destinationPage.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" export function trackSortingChangeEvent(sortOption: string) { trackEvent({ diff --git a/apps/scandic-web/utils/tracking/form.ts b/apps/scandic-web/utils/tracking/form.ts index 1bbf6aed4..a2b6a1566 100644 --- a/apps/scandic-web/utils/tracking/form.ts +++ b/apps/scandic-web/utils/tracking/form.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" export type FormType = "checkout" | "signup" diff --git a/apps/scandic-web/utils/tracking/hotelPage.ts b/apps/scandic-web/utils/tracking/hotelPage.ts index affa8c3ac..8c33fbb28 100644 --- a/apps/scandic-web/utils/tracking/hotelPage.ts +++ b/apps/scandic-web/utils/tracking/hotelPage.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" export function trackHotelMapClick() { trackEvent({ diff --git a/apps/scandic-web/utils/tracking/index.ts b/apps/scandic-web/utils/tracking/index.ts index fd09e2dcf..fc7783523 100644 --- a/apps/scandic-web/utils/tracking/index.ts +++ b/apps/scandic-web/utils/tracking/index.ts @@ -1,4 +1,3 @@ -export { trackClick } from "./base" export { trackBedSelection, trackBreakfastSelection, @@ -18,3 +17,4 @@ export { trackPageViewStart, } from "./pageview" export { trackPaymentEvent, trackUpdatePaymentMethod } from "./payment" +export { trackClick } from "@scandic-hotels/common/tracking/base" diff --git a/apps/scandic-web/utils/tracking/myStay.ts b/apps/scandic-web/utils/tracking/myStay.ts index 327ab582b..021499b08 100644 --- a/apps/scandic-web/utils/tracking/myStay.ts +++ b/apps/scandic-web/utils/tracking/myStay.ts @@ -1,8 +1,7 @@ import { CurrencyEnum } from "@scandic-hotels/common/constants/currency" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast" -import { trackEvent } from "./base" - import type { PackageSchema } from "@scandic-hotels/trpc/types/bookingConfirmation" import type { CreditCard } from "@scandic-hotels/trpc/types/user" diff --git a/apps/scandic-web/utils/tracking/navigation.ts b/apps/scandic-web/utils/tracking/navigation.ts index edf239ec3..00472dd40 100644 --- a/apps/scandic-web/utils/tracking/navigation.ts +++ b/apps/scandic-web/utils/tracking/navigation.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import type { TrackingPosition } from "@/types/components/tracking" diff --git a/apps/scandic-web/utils/tracking/pageview.ts b/apps/scandic-web/utils/tracking/pageview.ts index 2b623386f..a7ff3965b 100644 --- a/apps/scandic-web/utils/tracking/pageview.ts +++ b/apps/scandic-web/utils/tracking/pageview.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import type { TrackingSDKData } from "@/types/components/tracking" diff --git a/apps/scandic-web/utils/tracking/payment.ts b/apps/scandic-web/utils/tracking/payment.ts index ffa64e5a9..cccefff36 100644 --- a/apps/scandic-web/utils/tracking/payment.ts +++ b/apps/scandic-web/utils/tracking/payment.ts @@ -1,4 +1,4 @@ -import { trackEvent } from "./base" +import { trackEvent } from "@scandic-hotels/common/tracking/base" import type { PaymentEvent, diff --git a/packages/common/global.d.ts b/packages/common/global.d.ts index c218bf691..d6bb18798 100644 --- a/packages/common/global.d.ts +++ b/packages/common/global.d.ts @@ -2,4 +2,14 @@ import type { DataCache } from "./dataCache/Cache" declare global { var cacheClient: Promise | undefined + + interface Window { + dataLayer: { + [key: string]: any + push: (...args: unknown) => void + } + adobeDataLayer: { + push: (...args: unknown) => void + } + } } diff --git a/apps/scandic-web/hooks/useSessionId.ts b/packages/common/hooks/useSessionId.ts similarity index 100% rename from apps/scandic-web/hooks/useSessionId.ts rename to packages/common/hooks/useSessionId.ts diff --git a/packages/common/package.json b/packages/common/package.json index 0d97dcd1e..644f61a6f 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -15,6 +15,7 @@ "./dataCache": "./dataCache/index.ts", "./telemetry": "./telemetry/index.ts", "./tokenManager": "./tokenManager/index.ts", + "./tracking/base": "./tracking/base.ts", "./dt": "./dt/dt.ts", "./logger": "./logger/index.ts", "./logger/*": "./logger/*.ts", @@ -52,6 +53,7 @@ "deepmerge": "^4.3.1", "flat": "^6.0.1", "lodash-es": "^4.17.21", + "nanoid": "^5.1.5", "zod": "^3.24.4", "zustand": "^4.5.2" }, diff --git a/apps/scandic-web/utils/tracking/base.ts b/packages/common/tracking/base.ts similarity index 86% rename from apps/scandic-web/utils/tracking/base.ts rename to packages/common/tracking/base.ts index 9a621e267..55adcdb6e 100644 --- a/apps/scandic-web/utils/tracking/base.ts +++ b/packages/common/tracking/base.ts @@ -1,8 +1,7 @@ "use client" -import { logger } from "@scandic-hotels/common/logger" - -import { SESSION_ID_KEY_NAME } from "@/hooks/useSessionId" +import { SESSION_ID_KEY_NAME } from "../hooks/useSessionId" +import { logger } from "../logger" export function trackEvent(data: any) { if ( diff --git a/yarn.lock b/yarn.lock index 04ed6e05c..252bea92c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6158,6 +6158,7 @@ __metadata: eslint-plugin-simple-import-sort: "npm:^12.1.1" flat: "npm:^6.0.1" lodash-es: "npm:^4.17.21" + nanoid: "npm:^5.1.5" typescript: "npm:5.8.3" vitest: "npm:^3.2.4" zod: "npm:^3.24.4"