diff --git a/hooks/useSessionId.ts b/hooks/useSessionId.ts index 3a14a5027..ebf32b812 100644 --- a/hooks/useSessionId.ts +++ b/hooks/useSessionId.ts @@ -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() diff --git a/types/components/tracking.ts b/types/components/tracking.ts index a4c9e30d5..1eb629a99 100644 --- a/types/components/tracking.ts +++ b/types/components/tracking.ts @@ -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 {