Skip to content

Commit

Permalink
feat(clerk-react,shared): Add telemetry events for React hooks (#3341)
Browse files Browse the repository at this point in the history
* feat(clerk-react,shared): Add telemetry events for React hooks

* perf(clerk-react,shared): Remove `useEffect` from telemetry calls
  • Loading branch information
LauraBeatris committed May 7, 2024
1 parent bfcc5de commit 1662aaa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/chatty-jeans-fry.md
@@ -0,0 +1,8 @@
---
'@clerk/shared': patch
'@clerk/clerk-react': patch
---

The following are all internal changes and not relevant to any end-user:

Add telemetry events for `useSignIn`, `useSignUp`, `useOrganizations` and `useOrganizationList`
3 changes: 3 additions & 0 deletions packages/react/src/hooks/useSignIn.ts
@@ -1,4 +1,5 @@
import { useClientContext } from '@clerk/shared/react';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { SetActive, SignInResource } from '@clerk/types';

import { useIsomorphicClerkContext } from '../contexts/IsomorphicClerkContext';
Expand All @@ -24,6 +25,8 @@ export const useSignIn: UseSignIn = () => {
const isomorphicClerk = useIsomorphicClerkContext();
const client = useClientContext();

isomorphicClerk.telemetry?.record(eventMethodCalled('useSignIn'));

if (!client) {
return { isLoaded: false, signIn: undefined, setActive: undefined };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/hooks/useSignUp.ts
@@ -1,4 +1,5 @@
import { useClientContext } from '@clerk/shared/react';
import { eventMethodCalled } from '@clerk/shared/telemetry';
import type { SetActive, SignUpResource } from '@clerk/types';

import { useIsomorphicClerkContext } from '../contexts/IsomorphicClerkContext';
Expand All @@ -24,6 +25,8 @@ export const useSignUp: UseSignUp = () => {
const isomorphicClerk = useIsomorphicClerkContext();
const client = useClientContext();

isomorphicClerk.telemetry?.record(eventMethodCalled('useSignUp'));

if (!client) {
return { isLoaded: false, signUp: undefined, setActive: undefined };
}
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/react/hooks/useOrganization.tsx
Expand Up @@ -11,6 +11,7 @@ import type {
OrganizationResource,
} from '@clerk/types';

import { eventMethodCalled } from '../../telemetry/events/method-called';
import {
useAssertWrappedByClerkProvider,
useClerkInstanceContext,
Expand Down Expand Up @@ -135,6 +136,8 @@ export const useOrganization: UseOrganization = params => {

const clerk = useClerkInstanceContext();

clerk.telemetry?.record(eventMethodCalled('useOrganization'));

const domainParams =
typeof domainListParams === 'undefined'
? undefined
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/react/hooks/useOrganizationList.tsx
Expand Up @@ -11,6 +11,7 @@ import type {
UserOrganizationInvitationResource,
} from '@clerk/types';

import { eventMethodCalled } from '../../telemetry/events/method-called';
import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useUserContext } from '../contexts';
import type { PaginatedHookConfig, PaginatedResources, PaginatedResourcesWithDefault } from '../types';
import { usePagesOrInfinite, useWithSafeValues } from './usePagesOrInfinite';
Expand Down Expand Up @@ -99,6 +100,8 @@ export const useOrganizationList: UseOrganizationList = params => {
const clerk = useClerkInstanceContext();
const user = useUserContext();

clerk.telemetry?.record(eventMethodCalled('useOrganizationList'));

const userMembershipsParams =
typeof userMemberships === 'undefined'
? undefined
Expand Down

0 comments on commit 1662aaa

Please sign in to comment.