📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Refactoring
Blue Mouse25da50ca70f6
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.tsindex cec779eab..888e83a68 100644--- a/backend/apps/cloud/src/analytics/analytics.service.ts+++ b/backend/apps/cloud/src/analytics/analytics.service.ts@@ -374,21 +374,33 @@ export class AnalyticsService {path: string | null | undefined,endpoint: BotEndpoint,): Promise<BotDetectionResult> {- const result = await this.botDetectionService.detect({- pid,- userAgent,- headers,- ip,- referrer: referrer ?? null,- path: path ?? null,- endpoint,- })+ // Fail open: if bot detection itself errors (e.g. Redis is down inside+ // getRedisProject), treat the request as legitimate so ingestion is not+ // blocked by an unrelated infrastructure issue.+ let result: BotDetectionResult+ try {+ result = await this.botDetectionService.detect({+ pid,+ userAgent,+ headers,+ ip,+ referrer: referrer ?? null,+ path: path ?? null,+ endpoint,+ })+ } catch (reason) {+ this.logger.warn(+ `Bot detection failed for pid ${pid} (${endpoint}): ${reason}`,+ 'checkBot',+ )+ return { isBot: false, reason: null }+ }if (result.isBot && result.reason) {const { country } = getIPDetails(ip)- try {- await clickhouse.insert({+ clickhouse+ .insert({table: 'bot_blocks',format: 'JSONEachRow',values: [@@ -401,12 +413,12 @@ export class AnalyticsService {],clickhouse_settings: { async_insert: 1 },})- } catch (reason) {- this.logger.warn(- `Failed to log bot_block for pid ${pid}: ${reason}`,- 'checkBot',- )- }+ .catch((reason) => {+ this.logger.warn(+ `Failed to log bot_block for pid ${pid}: ${reason}`,+ 'checkBot',+ )+ })}return resultdiff --git a/backend/apps/cloud/src/analytics/bot-detection.service.ts b/backend/apps/cloud/src/analytics/bot-detection.service.tsindex 3c03ca736..79175a021 100644--- a/backend/apps/cloud/src/analytics/bot-detection.service.ts+++ b/backend/apps/cloud/src/analytics/bot-detection.service.ts@@ -45,7 +45,7 @@ const NEGATIVE: BotDetectionResult = {}const HEADLESS_PATTERN =- /HeadlessChrome|PhantomJS|SlimerJS|Selenium|WebDriver|Puppeteer|Playwright|Electron|Cypress|Nightmare|Splash/i+ /HeadlessChrome|PhantomJS|SlimerJS|Selenium|WebDriver|Puppeteer|Playwright|Cypress|Nightmare|Splash/i// Paths that almost exclusively appear in vulnerability scans / probes.// Conservative on purpose: WordPress admin paths (`/wp-admin`, `/wp-login.php`),@@ -73,8 +73,8 @@ const PROBE_PATH_PREFIXES: readonly string[] = ['/composer.phar','/vendor/phpunit','/vendor/composer',- '/owa/',- '/ecp/',+ '/owa',+ '/ecp','/autodiscover.xml','/HNAP1','/boaform',diff --git a/backend/apps/community/src/analytics/analytics.service.ts b/backend/apps/community/src/analytics/analytics.service.tsindex 32f896896..a7a80c1c9 100644--- a/backend/apps/community/src/analytics/analytics.service.ts+++ b/backend/apps/community/src/analytics/analytics.service.ts@@ -369,21 +369,33 @@ export class AnalyticsService {path: string | null | undefined,endpoint: BotEndpoint,): Promise<BotDetectionResult> {- const result = await this.botDetectionService.detect({- pid,- userAgent,- headers,- ip,- referrer: referrer ?? null,- path: path ?? null,- endpoint,- })+ // Fail open: if bot detection itself errors (e.g. Redis is down inside+ // getRedisProject), treat the request as legitimate so ingestion is not+ // blocked by an unrelated infrastructure issue.+ let result: BotDetectionResult+ try {+ result = await this.botDetectionService.detect({+ pid,+ userAgent,+ headers,+ ip,+ referrer: referrer ?? null,+ path: path ?? null,+ endpoint,+ })+ } catch (reason) {+ this.logger.warn(+ `Bot detection failed for pid ${pid} (${endpoint}): ${reason}`,+ 'checkBot',+ )+ return { isBot: false, reason: null }+ }if (result.isBot && result.reason) {const { country } = getIPDetails(ip)- try {- await clickhouse.insert({+ clickhouse+ .insert({table: 'bot_blocks',format: 'JSONEachRow',values: [@@ -396,12 +408,12 @@ export class AnalyticsService {],clickhouse_settings: { async_insert: 1 },})- } catch (reason) {- this.logger.warn(- `Failed to log bot_block for pid ${pid}: ${reason}`,- 'checkBot',- )- }+ .catch((reason) => {+ this.logger.warn(+ `Failed to log bot_block for pid ${pid}: ${reason}`,+ 'checkBot',+ )+ })}return resultdiff --git a/backend/apps/community/src/analytics/bot-detection.service.ts b/backend/apps/community/src/analytics/bot-detection.service.tsindex db844a8bb..69553ad49 100644--- a/backend/apps/community/src/analytics/bot-detection.service.ts+++ b/backend/apps/community/src/analytics/bot-detection.service.ts@@ -45,7 +45,7 @@ const NEGATIVE: BotDetectionResult = {}const HEADLESS_PATTERN =- /HeadlessChrome|PhantomJS|SlimerJS|Selenium|WebDriver|Puppeteer|Playwright|Electron|Cypress|Nightmare|Splash/i+ /HeadlessChrome|PhantomJS|SlimerJS|Selenium|WebDriver|Puppeteer|Playwright|Cypress|Nightmare|Splash/i// Paths that almost exclusively appear in vulnerability scans / probes.// Conservative on purpose: WordPress admin paths (`/wp-admin`, `/wp-login.php`),@@ -73,8 +73,8 @@ const PROBE_PATH_PREFIXES: readonly string[] = ['/composer.phar','/vendor/phpunit','/vendor/composer',- '/owa/',- '/ecp/',+ '/owa',+ '/ecp','/autodiscover.xml','/HNAP1','/boaform',diff --git a/web/app/pages/Project/Settings/components/BotProtectionReport.tsx b/web/app/pages/Project/Settings/components/BotProtectionReport.tsxindex 29ddac5de..3699d3431 100644--- a/web/app/pages/Project/Settings/components/BotProtectionReport.tsx+++ b/web/app/pages/Project/Settings/components/BotProtectionReport.tsx@@ -83,7 +83,7 @@ const BotProtectionReport = ({ pid }: BotProtectionReportProps) => {const isInitialLoading = isLoading && !statsconst showData = !error && !isInitialLoading && total > 0- const showEmpty = !error && !isInitialLoading && stats !== null && total === 0+ const showEmpty = !error && !isInitialLoading && total === 0return (<section className='overflow-hidden rounded-lg border border-gray-200 bg-white dark:border-slate-800/60 dark:bg-slate-900/25'>