Download wp-calypso/client/dashboard/components/page-view-tracker/index.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 691 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/dashboard/components/page-view-tracker/index.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/dashboard/components/page-view-tracker/index.tsx
-
curl -L -o index.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/dashboard/components/page-view-tracker/index.tsx
691 Bytes
| import { useRouter } from '@tanstack/react-router'; | |
| import { useEffect, useRef } from 'react'; | |
| import { useAnalytics } from '../../app/analytics'; | |
| export function PageViewTracker() { | |
| const router = useRouter(); | |
| const { recordPageView } = useAnalytics(); | |
| const lastPath = useRef(); | |
| useEffect( () => { | |
| return router.subscribe( 'onResolved', () => { | |
| const leafMatch = router.state.matches.at( -1 ); | |
| const path = leafMatch?.context?.config?.basePath + leafMatch?.routeId; | |
| if ( path && ( ! lastPath.current || lastPath.current !== path ) ) { | |
| recordPageView( path, document.title ); | |
| lastPath.current = path; | |
| } | |
| } ); | |
| }, [ router, recordPageView ] ); | |
| return null; | |
| } | |