From e444985295c7743b1bb1c485349fcd41b8941bad Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Mon, 16 Mar 2026 16:59:37 +0100 Subject: [PATCH] refactor: extract frustration tracking into separate add-on script Move rage click and dead click detection (35% of script.js) into script.frustration.js as an optional add-on. Core script drops from 8.1KB to 5.7KB gzipped. Add-on auto-discovers core via window.pulse polling and supports opt-out via data-no-rage/data-no-dead attributes. - Expose cleanPath on window.pulse for add-on consumption - Add script.frustration.js to middleware PUBLIC_ROUTES - Update integration guides, ScriptSetupBlock, and FrustrationTable empty state to reference the add-on script --- components/IntegrationGuide.tsx | 12 + components/behavior/FrustrationTable.tsx | 5 +- components/sites/ScriptSetupBlock.tsx | 3 + middleware.ts | 1 + public/script.frustration.js | 313 +++++++++++++++++++++++ public/script.js | 271 +------------------- 6 files changed, 334 insertions(+), 271 deletions(-) create mode 100644 public/script.frustration.js diff --git a/components/IntegrationGuide.tsx b/components/IntegrationGuide.tsx index efca796..fb53861 100644 --- a/components/IntegrationGuide.tsx +++ b/components/IntegrationGuide.tsx @@ -67,6 +67,18 @@ export function IntegrationGuide({ integration, children }: IntegrationGuideProp
{children} + +
+

Optional: Frustration Tracking

+

+ Detect rage clicks and dead clicks by adding the frustration tracking + add-on after the core script: +

+
{``}
+

+ No extra configuration needed. Add data-no-rage or{' '} + data-no-dead to disable individual signals. +

{/* * --- Related Integrations --- */} diff --git a/components/behavior/FrustrationTable.tsx b/components/behavior/FrustrationTable.tsx index 8294b95..916b749 100644 --- a/components/behavior/FrustrationTable.tsx +++ b/components/behavior/FrustrationTable.tsx @@ -184,8 +184,11 @@ export default function FrustrationTable({ No {title.toLowerCase()} detected

- {description}. Data will appear here once frustration signals are detected on your site. + Frustration tracking requires the add-on script. Add it after your core Pulse script:

+ + {''} + )} diff --git a/components/sites/ScriptSetupBlock.tsx b/components/sites/ScriptSetupBlock.tsx index b853f27..fe3c44d 100644 --- a/components/sites/ScriptSetupBlock.tsx +++ b/components/sites/ScriptSetupBlock.tsx @@ -92,6 +92,9 @@ export default function ScriptSetupBlock({

Default: cross-tab (localStorage). Optional: data-storage="session" to opt out (per-tab, ephemeral). Optional: data-storage-ttl="48" to set expiry in hours (default: 24).

+

+ Optional: add {``} for rage click and dead click detection. +