11'use client' ;
22import { useEffect } from 'react' ;
3- import { usePlausible } from 'next-plausible' ;
43
4+ import { usePlausibleEvent } from 'sentry-docs/hooks/usePlausibleEvent' ;
5+ import { PROGRESS_MILESTONES , ReadProgressMilestone } from 'sentry-docs/types/plausible' ;
56import { debounce } from 'sentry-docs/utils' ;
67
7- const EVENT = 'Read Progress' ;
8- const milestones = [ 25 , 50 , 75 , 100 ] as const ;
9- type Milestone = ( typeof milestones ) [ number ] ;
10- type EVENT_PROPS = { page : string ; readProgress : Milestone } ;
11-
128export function ReaderDepthTracker ( ) {
13- const plausible = usePlausible < { [ EVENT ] : EVENT_PROPS } > ( ) ;
9+ const { emit } = usePlausibleEvent ( ) ;
1410
15- const sendProgressToPlausible = ( progress : Milestone ) => {
16- plausible ( EVENT , { props : { readProgress : progress , page : document . title } } ) ;
11+ const sendProgressToPlausible = ( progress : ReadProgressMilestone ) => {
12+ emit ( 'Read Progress' , { props : { readProgress : progress , page : document . title } } ) ;
1713 } ;
1814
1915 useEffect ( ( ) => {
20- const reachedMilestones = new Set < Milestone > ( ) ;
16+ const reachedMilestones = new Set < ReadProgressMilestone > ( ) ;
2117
2218 const trackProgress = ( ) => {
2319 // calculate the progress based on the scroll position
@@ -30,7 +26,7 @@ export function ReaderDepthTracker() {
3026 }
3127
3228 // find the biggest milestone that has not been reached yet
33- const milestone = milestones . findLast (
29+ const milestone = PROGRESS_MILESTONES . findLast (
3430 m =>
3531 progress >= m &&
3632 ! reachedMilestones . has ( m ) &&
0 commit comments