Merged in feat/sw-3322-move-base-tracking-to-common (pull request #2713)

feat(SW-3322): Move base tracking to common package

* Move base tracking to common package

* Update lock file


Approved-by: Joakim Jäderberg
This commit is contained in:
Anton Gunnarsson
2025-08-27 12:29:46 +00:00
parent 45a8fd8c43
commit e4a66499e5
25 changed files with 37 additions and 25 deletions

View File

@@ -0,0 +1,22 @@
import { nanoid } from "nanoid"
import { useMemo } from "react"
export const SESSION_ID_KEY_NAME = "web_sessionId"
export function useSessionId(): string | null {
const sessionId = useMemo(() => {
if (typeof window === "undefined") {
// Return null if running on the server
return null
}
let currentSessionId = sessionStorage.getItem(SESSION_ID_KEY_NAME)
if (!currentSessionId) {
currentSessionId = nanoid()
sessionStorage.setItem(SESSION_ID_KEY_NAME, currentSessionId)
}
return currentSessionId
}, [])
return sessionId
}