@databiosphere/findable-ui 52.1.0 → 52.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common/analytics/entities.d.ts +5 -1
- package/lib/common/analytics/entities.js +1 -0
- package/lib/google/provider.js +2 -0
- package/lib/hooks/authentication/useLoginTracking.d.ts +9 -0
- package/lib/hooks/authentication/useLoginTracking.js +25 -0
- package/lib/nextauth/provider.js +2 -0
- package/package.json +1 -1
|
@@ -13,7 +13,8 @@ export declare enum EVENT_NAME {
|
|
|
13
13
|
FILE_DOWNLOADED = "file_downloaded",
|
|
14
14
|
FILTER_SELECTED = "filter_selected",
|
|
15
15
|
INDEX_ANALYZE_IN_TERRA_REQUESTED = "index_analyze_in_terra_requested",
|
|
16
|
-
INDEX_FILE_MANIFEST_REQUESTED = "index_file_manifest_requested"
|
|
16
|
+
INDEX_FILE_MANIFEST_REQUESTED = "index_file_manifest_requested",
|
|
17
|
+
LOGIN = "login"
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Set of analytics event parameters.
|
|
@@ -78,4 +79,7 @@ export type EventParams = {
|
|
|
78
79
|
[EVENT_NAME.INDEX_FILE_MANIFEST_REQUESTED]: {
|
|
79
80
|
[EVENT_PARAM.ENTITY_NAME]: string;
|
|
80
81
|
};
|
|
82
|
+
[EVENT_NAME.LOGIN]: {
|
|
83
|
+
[EVENT_PARAM.TOOL_NAME]: string;
|
|
84
|
+
};
|
|
81
85
|
};
|
|
@@ -14,6 +14,7 @@ export var EVENT_NAME;
|
|
|
14
14
|
EVENT_NAME["FILTER_SELECTED"] = "filter_selected";
|
|
15
15
|
EVENT_NAME["INDEX_ANALYZE_IN_TERRA_REQUESTED"] = "index_analyze_in_terra_requested";
|
|
16
16
|
EVENT_NAME["INDEX_FILE_MANIFEST_REQUESTED"] = "index_file_manifest_requested";
|
|
17
|
+
EVENT_NAME["LOGIN"] = "login";
|
|
17
18
|
})(EVENT_NAME || (EVENT_NAME = {}));
|
|
18
19
|
/**
|
|
19
20
|
* Set of analytics event parameters.
|
package/lib/google/provider.js
CHANGED
|
@@ -8,6 +8,7 @@ import { useCredentialsReducer } from "../auth/hooks/useCredentialsReducer";
|
|
|
8
8
|
import { useSessionIdleTimer } from "../auth/hooks/useSessionIdleTimer";
|
|
9
9
|
import { useSessionActive } from "../hooks/authentication/session/useSessionActive";
|
|
10
10
|
import { useSessionCallbackUrl } from "../hooks/authentication/session/useSessionCallbackUrl";
|
|
11
|
+
import { useLoginTracking } from "../hooks/authentication/useLoginTracking";
|
|
11
12
|
import { AUTH_STATE, AUTHENTICATION_STATE } from "./constants";
|
|
12
13
|
import { useGoogleSignInService } from "./hooks/useGoogleSignInService";
|
|
13
14
|
import { useTokenReducer } from "./hooks/useTokenReducer";
|
|
@@ -35,6 +36,7 @@ export function GoogleSignInAuthenticationProvider({ children, SessionController
|
|
|
35
36
|
const { authDispatch, authState } = authReducer;
|
|
36
37
|
const { isAuthenticated } = authState;
|
|
37
38
|
const { authenticationState } = authenticationReducer;
|
|
39
|
+
useLoginTracking(isAuthenticated, authState.status);
|
|
38
40
|
useSessionActive(authState, authenticationState);
|
|
39
41
|
useSessionIdleTimer({
|
|
40
42
|
disabled: !isAuthenticated,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AUTH_STATUS } from "../../auth/types/auth";
|
|
2
|
+
/**
|
|
3
|
+
* Tracks a GA4 login event when the user transitions from unauthenticated to authenticated.
|
|
4
|
+
* Does not fire during initial session hydration or on mount if already authenticated.
|
|
5
|
+
* @param isAuthenticated - Current authentication state.
|
|
6
|
+
* @param status - Current auth status; tracking only begins after status has settled.
|
|
7
|
+
* @returns void.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useLoginTracking(isAuthenticated: boolean, status: AUTH_STATUS): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { AUTH_STATUS } from "../../auth/types/auth";
|
|
3
|
+
import { track } from "../../common/analytics/analytics";
|
|
4
|
+
import { EVENT_NAME, EVENT_PARAM } from "../../common/analytics/entities";
|
|
5
|
+
import { GOOGLE_SIGN_IN_PROVIDER_ID } from "../../google/constants";
|
|
6
|
+
/**
|
|
7
|
+
* Tracks a GA4 login event when the user transitions from unauthenticated to authenticated.
|
|
8
|
+
* Does not fire during initial session hydration or on mount if already authenticated.
|
|
9
|
+
* @param isAuthenticated - Current authentication state.
|
|
10
|
+
* @param status - Current auth status; tracking only begins after status has settled.
|
|
11
|
+
* @returns void.
|
|
12
|
+
*/
|
|
13
|
+
export function useLoginTracking(isAuthenticated, status) {
|
|
14
|
+
const wasAuthenticated = useRef(undefined);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (status !== AUTH_STATUS.SETTLED)
|
|
17
|
+
return;
|
|
18
|
+
if (wasAuthenticated.current === false && isAuthenticated) {
|
|
19
|
+
track(EVENT_NAME.LOGIN, {
|
|
20
|
+
[EVENT_PARAM.TOOL_NAME]: GOOGLE_SIGN_IN_PROVIDER_ID,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
wasAuthenticated.current = isAuthenticated;
|
|
24
|
+
}, [isAuthenticated, status]);
|
|
25
|
+
}
|
package/lib/nextauth/provider.js
CHANGED
|
@@ -6,6 +6,7 @@ import { useAuthenticationReducer } from "../auth/hooks/useAuthenticationReducer
|
|
|
6
6
|
import { useAuthReducer } from "../auth/hooks/useAuthReducer";
|
|
7
7
|
import { useSessionIdleTimer } from "../auth/hooks/useSessionIdleTimer";
|
|
8
8
|
import { useSessionCallbackUrl } from "../hooks/authentication/session/useSessionCallbackUrl";
|
|
9
|
+
import { useLoginTracking } from "../hooks/authentication/useLoginTracking";
|
|
9
10
|
import { useNextAuthService } from "./hooks/useNextAuthService";
|
|
10
11
|
import { SessionController } from "./session-controller";
|
|
11
12
|
/**
|
|
@@ -23,6 +24,7 @@ export function NextAuthAuthenticationProvider({ children, refetchInterval = 0,
|
|
|
23
24
|
const service = useNextAuthService();
|
|
24
25
|
const { authDispatch, authState } = authReducer;
|
|
25
26
|
const { isAuthenticated } = authState;
|
|
27
|
+
useLoginTracking(isAuthenticated, authState.status);
|
|
26
28
|
const { callbackUrl } = useSessionCallbackUrl();
|
|
27
29
|
useSessionIdleTimer({
|
|
28
30
|
crossTab: true,
|