From 1a3b43fa0f38351ec3a37e9071c91974823fe0b8 Mon Sep 17 00:00:00 2001 From: Adamski Date: Wed, 28 Aug 2024 19:10:31 +0200 Subject: [PATCH] chore: useSession hook; events url change; --- src/hooks/useJumperTracking.ts | 4 ++++ src/hooks/useSession.ts | 18 ++++++++++-------- src/hooks/userTracking/useUserTracking.ts | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/hooks/useJumperTracking.ts b/src/hooks/useJumperTracking.ts index eb3c0bb78..49a770436 100644 --- a/src/hooks/useJumperTracking.ts +++ b/src/hooks/useJumperTracking.ts @@ -65,6 +65,8 @@ export interface JumperDataTrackTransactionProps { errorCode?: string | number; errorMessage?: string; pathname?: string; + url: string; + browserFingerprint: string; } export const useJumperTracking = () => { @@ -113,6 +115,8 @@ export const useJumperTracking = () => { errorMessage: data.errorMessage, errorCode: data.errorCode, pathname: data.pathname, + url: data.url, + browserFingerprint: data.browserFingerprint, }; await track(transactionData, JUMPER_ANALYTICS_TRANSACTION); }; diff --git a/src/hooks/useSession.ts b/src/hooks/useSession.ts index e357e337a..6573e4686 100644 --- a/src/hooks/useSession.ts +++ b/src/hooks/useSession.ts @@ -2,22 +2,24 @@ import { useEffect, useState } from 'react'; import { v7 as uuidv7 } from 'uuid'; -export const useSession = (): string | undefined => { - const [session, setSession] = useState(() => { +export const useSession = (): string => { + const [session, setSession] = useState(() => { if ( typeof window !== 'undefined' && typeof sessionStorage !== 'undefined' ) { - return sessionStorage.getItem('session_id') || undefined; + return sessionStorage.getItem('session_id') || uuidv7(); } - return undefined; + return uuidv7(); }); useEffect(() => { - if (!session) { - const newSessionId = uuidv7(); - setSession(newSessionId); - sessionStorage.setItem('session_id', newSessionId); + if ( + typeof window !== 'undefined' && + typeof sessionStorage !== 'undefined' + ) { + sessionStorage.setItem('session_id', session); + setSession(session); } }, [session]); diff --git a/src/hooks/userTracking/useUserTracking.ts b/src/hooks/userTracking/useUserTracking.ts index 882227425..4d93c27d4 100644 --- a/src/hooks/userTracking/useUserTracking.ts +++ b/src/hooks/userTracking/useUserTracking.ts @@ -124,7 +124,7 @@ export function useUserTracking() { browserFingerprint: fp, isMobile: !isDesktop, sessionId: sessionId || 'unknown', - url: process.env.NEXT_PUBLIC_SITE_URL, + url: window?.location?.href, }; await jumperTrackEvent(eventData); } catch (error) { @@ -199,6 +199,8 @@ export function useUserTracking() { errorCode: data[TrackingEventParameter.ErrorCode], errorMessage: data[TrackingEventParameter.ErrorMessage], action: data[TrackingEventParameter.Action] || '', + url: window?.location?.href, + browserFingerprint: fp, }; await jumperTrackTransaction(transactionData); }