From 71a49d58ec52deb26c4e918b22756b1717ca6e93 Mon Sep 17 00:00:00 2001 From: Dhiraj Kumar Azad Date: Mon, 9 Mar 2026 14:23:37 +0530 Subject: [PATCH] Added changes for scarf pixel --- docusaurus.config.js | 4 ++++ src/clientModules/scarfAnalytics.js | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/clientModules/scarfAnalytics.js diff --git a/docusaurus.config.js b/docusaurus.config.js index 61b6ba8..40c4594 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -24,6 +24,10 @@ const config = { onBrokenLinks: 'warn', onBrokenMarkdownLinks: 'warn', + clientModules: [ + './src/clientModules/scarfAnalytics.js', + ], + // Even if you don't use internationalization, you can use this field to set // useful metadata like html lang. For example, if your site is Chinese, you // may want to replace "en" with "zh-Hans". diff --git a/src/clientModules/scarfAnalytics.js b/src/clientModules/scarfAnalytics.js new file mode 100644 index 0000000..08d4fc1 --- /dev/null +++ b/src/clientModules/scarfAnalytics.js @@ -0,0 +1,24 @@ +// Scarf pixel – SPA-aware tracking for the Docusaurus documentation site. +// This client module fires on the initial page load and on every subsequent +// in-app navigation so that each page view is recorded, even in a SPA where +// the full page is never reloaded. + +const PIXEL_ID = '5ff443aa-dd19-43ab-9c9e-ad26252d0fb0'; + +let lastHref = null; + +function sendScarfPing() { + const currentHref = window.location.href; + if (currentHref === lastHref) return; // dedup: skip if same page + lastHref = currentHref; + + const img = new Image(); + img.referrerPolicy = 'no-referrer-when-downgrade'; + img.src = `https://static.scarf.sh/a.png?x-pxid=${PIXEL_ID}`; +} + +// Docusaurus client-module lifecycle hook – called after every route update +// (initial load + every SPA navigation). +export function onRouteDidUpdate() { + sendScarfPing(); +}