Skip to content

Commit

Permalink
chore: useSession hook; events url change;
Browse files Browse the repository at this point in the history
  • Loading branch information
admsk2 authored Aug 28, 2024
1 parent c683c3b commit 1a3b43f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/hooks/useJumperTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export interface JumperDataTrackTransactionProps {
errorCode?: string | number;
errorMessage?: string;
pathname?: string;
url: string;
browserFingerprint: string;
}

export const useJumperTracking = () => {
Expand Down Expand Up @@ -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);
};
Expand Down
18 changes: 10 additions & 8 deletions src/hooks/useSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
import { useEffect, useState } from 'react';
import { v7 as uuidv7 } from 'uuid';

export const useSession = (): string | undefined => {
const [session, setSession] = useState<string | undefined>(() => {
export const useSession = (): string => {
const [session, setSession] = useState<string>(() => {
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]);

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/userTracking/useUserTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1a3b43f

Please sign in to comment.