Skip to content

Commit 282f2a8

Browse files
Added scarf analytics
1 parent 2ded5e6 commit 282f2a8

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

docusaurus/docusaurus.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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',

docusaurus/src/scarf.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)