Merged in feat/SW-1909-update-adobe-on-language-change (pull request #1526)

feat(SW-1909): Fix Adobe Data Layer not updating during language changes

* feat(SW-1909): Update Tracking on language changes


Approved-by: Linus Flood
This commit is contained in:
Chuma Mcphoy (We Ahead)
2025-03-13 08:25:50 +00:00
parent bb599d4679
commit 550474dffe
2 changed files with 54 additions and 16 deletions

View File

@@ -8,6 +8,12 @@ interface TrackingStoreState {
initialStartTime: number
setInitialPageLoadTime: (time: number) => void
getPageLoadTime: () => number
currentPath: string | null
previousPath: string | null
currentLang: string | null
previousLang: string | null
updateRouteInfo: (path: string, lang: string) => void
hasPathOrLangChanged: () => boolean
}
const useTrackingStore = create<TrackingStoreState>((set, get) => ({
@@ -19,6 +25,37 @@ const useTrackingStore = create<TrackingStoreState>((set, get) => ({
const { initialStartTime } = get()
return (Date.now() - initialStartTime) / 1000
},
currentPath: null,
previousPath: null,
currentLang: null,
previousLang: null,
updateRouteInfo: (path, lang) =>
set((state) => {
if (!path || !lang) return state
if (!state.currentPath || !state.currentLang) {
return {
currentPath: path,
currentLang: lang,
previousPath: null,
previousLang: null,
}
}
return {
previousPath: state.currentPath,
previousLang: state.currentLang,
currentPath: path,
currentLang: lang,
}
}),
hasPathOrLangChanged: () => {
const { currentPath, previousPath, currentLang, previousLang } = get()
if (!previousPath || !previousLang) return false
return currentPath !== previousPath || currentLang !== previousLang
},
}))
export default useTrackingStore