Check if client for session id hook

This commit is contained in:
Linus Flood
2024-12-03 14:20:13 +01:00
parent b9111511b7
commit adf6095762
2 changed files with 7 additions and 2 deletions

View File

@@ -3,8 +3,13 @@ import { v4 as uuidv4 } from "uuid"
const storageKey = "sessionId"
export function useSessionId(): string {
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(storageKey)
if (!currentSessionId) {
currentSessionId = uuidv4()

View File

@@ -23,7 +23,7 @@ export type TrackingSDKPageData = {
domain?: string
siteSections: string
pageLoadTime?: number // Page load time in seconds
sessionId?: string
sessionId?: string | null
}
export enum LoginTypeEnum {