Merged in feat/tracking-sessionId (pull request #1653)

Feat(tracking): add sessionId to all events. Fixed some invalid session bugs

* Feat(tracking): add sessionId to all events. Fixed some invalid session bugs


Approved-by: Anton Gunnarsson
This commit is contained in:
Linus Flood
2025-03-27 10:42:24 +00:00
parent 5de2a993a7
commit 0f9c9c2af8
5 changed files with 20 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
import { nanoid } from "nanoid"
import { useMemo } from "react"
const storageKey = "web_sessionId"
export const SESSION_ID_KEY_NAME = "web_sessionId"
export function useSessionId(): string | null {
const sessionId = useMemo(() => {
@@ -10,10 +10,10 @@ export function useSessionId(): string | null {
return null
}
let currentSessionId = sessionStorage.getItem(storageKey)
let currentSessionId = sessionStorage.getItem(SESSION_ID_KEY_NAME)
if (!currentSessionId) {
currentSessionId = nanoid()
sessionStorage.setItem(storageKey, currentSessionId)
sessionStorage.setItem(SESSION_ID_KEY_NAME, currentSessionId)
}
return currentSessionId
}, [])