From 69814bcc6836991b6033f2a08e4b4851be85f1dc Mon Sep 17 00:00:00 2001 From: ner Date: Mon, 28 Sep 2026 11:12:53 +0300 Subject: [PATCH] feat(analytics): filter bot traffic client-side via SDK filter option --- components/Analytics/index.tsx | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/components/Analytics/index.tsx b/components/Analytics/index.tsx index feca3bc..b2a516c 100644 --- a/components/Analytics/index.tsx +++ b/components/Analytics/index.tsx @@ -9,12 +9,23 @@ const SCRIPT_ID = 'openpanel-sdk'; const SRC = OPENPANEL_SCRIPT_URL || 'https://openpanel.dev/op1.js'; -const OPTIONS = { - clientId: OPENPANEL_CLIENT_ID, - apiUrl: OPENPANEL_API_URL, - trackScreenViews: true, - trackOutgoingLinks: true -}; +const BOT_FILTER = `function () { + try { + const ua = navigator.userAgent; + + return !/bot|crawl|spider|headless|lighthouse|prerender|slurp/i.test(ua) && !navigator.webdriver; + } catch { + return true; + } +}`; + +const INIT_OPTIONS = [ + `clientId: ${JSON.stringify(OPENPANEL_CLIENT_ID)}`, + `apiUrl: ${JSON.stringify(OPENPANEL_API_URL)}`, + 'trackScreenViews: true', + 'trackOutgoingLinks: true', + `filter: ${BOT_FILTER}` +].join(', '); const Analytics = () => { useEffect(() => { @@ -52,7 +63,7 @@ const Analytics = () => { return (