Skip to content

Elef/track more hooks #6158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fresh-regions-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Track telemetry of hooks
1 change: 1 addition & 0 deletions packages/shared/src/react/hooks/useReverification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function createReverificationHandler(params: CreateReverificationHandlerParams)
* On success resolve the pending promise
* On cancel reject the pending promise
*/
// Do we need to log telemetry here as well ?
params.openUIComponent?.({
level: level,
afterVerification: complete,
Expand Down
11 changes: 7 additions & 4 deletions packages/shared/src/react/hooks/useSession.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { PendingSessionOptions, UseSessionReturn } from '@clerk/types';

import { useAssertWrappedByClerkProvider, useSessionContext } from '../contexts';
import { useClerk } from './useClerk';
import { eventMethodCalled } from '../../telemetry/events/method-called';
import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useSessionContext } from '../contexts';

type UseSession = (options?: PendingSessionOptions) => UseSessionReturn;

const hookName = `useSession`;
/**
* The `useSession()` hook provides access to the current user's [`Session`](https://clerk.com/docs/references/javascript/session) object, as well as helpers for setting the active session.
*
Expand Down Expand Up @@ -55,10 +56,12 @@ type UseSession = (options?: PendingSessionOptions) => UseSessionReturn;
* </Tabs>
*/
export const useSession: UseSession = (options = {}) => {
useAssertWrappedByClerkProvider('useSession');
useAssertWrappedByClerkProvider(hookName);

const session = useSessionContext();
const clerk = useClerk();
const clerk = useClerkInstanceContext();

clerk.telemetry?.record(eventMethodCalled(hookName));

if (session === undefined) {
return { isLoaded: false, isSignedIn: undefined, session: undefined };
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/react/hooks/useSessionList.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { UseSessionListReturn } from '@clerk/types';

import { eventMethodCalled } from '../../telemetry/events/method-called';
import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useClientContext } from '../contexts';

const hookName = 'useSessionList';
/**
* The `useSessionList()` hook returns an array of [`Session`](https://clerk.com/docs/references/javascript/session) objects that have been registered on the client device.
*
Expand Down Expand Up @@ -46,10 +48,13 @@ import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useClientCont
* </Tabs>
*/
export const useSessionList = (): UseSessionListReturn => {
useAssertWrappedByClerkProvider('useSessionList');
useAssertWrappedByClerkProvider(hookName);

const isomorphicClerk = useClerkInstanceContext();
const client = useClientContext();
const clerk = useClerkInstanceContext();

clerk.telemetry?.record(eventMethodCalled(hookName));

if (!client) {
return { isLoaded: false, sessions: undefined, setActive: undefined };
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/react/hooks/useUser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { UseUserReturn } from '@clerk/types';

import { useAssertWrappedByClerkProvider, useUserContext } from '../contexts';
import { eventMethodCalled } from '../../telemetry/events/method-called';
import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useUserContext } from '../contexts';

const hookName = 'useUser';
/**
* The `useUser()` hook provides access to the current user's [`User`](https://clerk.com/docs/references/javascript/user) object, which contains all the data for a single user in your application and provides methods to manage their account. This hook also allows you to check if the user is signed in and if Clerk has loaded and initialized.
*
Expand Down Expand Up @@ -126,9 +128,12 @@ import { useAssertWrappedByClerkProvider, useUserContext } from '../contexts';
* </Tabs>
*/
export function useUser(): UseUserReturn {
useAssertWrappedByClerkProvider('useUser');
useAssertWrappedByClerkProvider(hookName);

const user = useUserContext();
const clerk = useClerkInstanceContext();

clerk.telemetry?.record(eventMethodCalled(hookName));

if (user === undefined) {
return { isLoaded: false, isSignedIn: undefined, user: undefined };
Expand Down
Loading