File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -111,6 +111,9 @@ const config = {
111111 searchPagePath : 'search' ,
112112 } ,
113113 } ) ,
114+ // Scarf pixel – fires on every page view (SPA-aware)
115+ clientModules : [ require . resolve ( './src/scarf.js' ) ] ,
116+
114117 plugins : [
115118 [
116119 'docusaurus-plugin-typedoc' ,
Original file line number Diff line number Diff line change 1+ // Scarf pixel – SPA-aware tracking for the Docusaurus documentation site.
2+ // This client module fires on the initial page load and on every subsequent
3+ // in-app navigation so that each page view is recorded, even in a SPA where
4+ // the full page is never reloaded.
5+
6+ const PIXEL_ID = '7c25872d-249e-45d8-aa99-0d0e3421c29e' ;
7+
8+ let lastHref = null ;
9+
10+ function sendScarfPing ( ) {
11+ if ( typeof window === 'undefined' ) return ;
12+
13+ const currentHref = window . location . href ;
14+ if ( currentHref === lastHref ) return ; // dedup: skip if same page
15+ lastHref = currentHref ;
16+
17+ const url = `https://static.scarf.sh/a.png?x-pxid=${ PIXEL_ID } ` ;
18+ const img = new Image ( ) ;
19+ img . referrerPolicy = 'no-referrer-when-downgrade' ;
20+ img . src = url ;
21+ }
22+
23+ // Docusaurus client-module lifecycle hook – called after every route update
24+ // (initial load + every SPA navigation).
25+ export function onRouteDidUpdate ( ) {
26+ sendScarfPing ( ) ;
27+ }
You can’t perform that action at this time.
0 commit comments