-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Track usage of pages and app router (#5236)
- Loading branch information
1 parent
3dbdde1
commit 382c302
Showing
8 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/nextjs': patch | ||
--- | ||
|
||
Track usage of pages and app router. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/shared': patch | ||
--- | ||
|
||
Update `TelemetryCollector` to throttle events after they've been sampled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { eventFrameworkMetadata } from '@clerk/shared/telemetry'; | ||
|
||
import { useClerk } from '../client-boundary/hooks'; | ||
import { usePagesRouter } from '../client-boundary/hooks/usePagesRouter'; | ||
|
||
const RouterTelemetry = () => { | ||
const clerk = useClerk(); | ||
const { pagesRouter } = usePagesRouter(); | ||
|
||
/** | ||
* Caching and throttling is handled internally it's safe to execute on every navigation. | ||
*/ | ||
clerk.telemetry?.record( | ||
eventFrameworkMetadata({ | ||
router: pagesRouter ? 'pages' : 'app', | ||
}), | ||
); | ||
|
||
return null; | ||
}; | ||
|
||
export { RouterTelemetry }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/shared/src/telemetry/events/framework-metadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { TelemetryEventRaw } from '@clerk/types'; | ||
|
||
const EVENT_FRAMEWORK_METADATA = 'FRAMEWORK_METADATA'; | ||
const EVENT_SAMPLING_RATE = 0.1; | ||
|
||
type EventFrameworkMetadata = Record<string, string | number | boolean>; | ||
|
||
/** | ||
* Fired when a helper method is called from a Clerk SDK. | ||
*/ | ||
export function eventFrameworkMetadata(payload: EventFrameworkMetadata): TelemetryEventRaw<EventFrameworkMetadata> { | ||
return { | ||
event: EVENT_FRAMEWORK_METADATA, | ||
eventSamplingRate: EVENT_SAMPLING_RATE, | ||
payload, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './component-mounted'; | ||
export * from './method-called'; | ||
export * from './framework-metadata'; |