File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ const config = {
2424 onBrokenLinks : 'warn' ,
2525 onBrokenMarkdownLinks : 'warn' ,
2626
27+ clientModules : [
28+ './src/clientModules/scarfAnalytics.js' ,
29+ ] ,
30+
2731 // Even if you don't use internationalization, you can use this field to set
2832 // useful metadata like html lang. For example, if your site is Chinese, you
2933 // may want to replace "en" with "zh-Hans".
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 = '5ff443aa-dd19-43ab-9c9e-ad26252d0fb0' ;
7+
8+ let lastHref = null ;
9+
10+ function sendScarfPing ( ) {
11+ const currentHref = window . location . href ;
12+ if ( currentHref === lastHref ) return ; // dedup: skip if same page
13+ lastHref = currentHref ;
14+
15+ const img = new Image ( ) ;
16+ img . referrerPolicy = 'no-referrer-when-downgrade' ;
17+ img . src = `https://static.scarf.sh/a.png?x-pxid=${ PIXEL_ID } ` ;
18+ }
19+
20+ // Docusaurus client-module lifecycle hook – called after every route update
21+ // (initial load + every SPA navigation).
22+ export function onRouteDidUpdate ( ) {
23+ sendScarfPing ( ) ;
24+ }
You can’t perform that action at this time.
0 commit comments