📈 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
/log/hb validations
Blue Mousea99be232dd07
diff --git a/backend/apps/production/src/analytics/analytics.controller.ts b/backend/apps/production/src/analytics/analytics.controller.tsindex 245e11b9f..56e61973c 100644--- a/backend/apps/production/src/analytics/analytics.controller.ts+++ b/backend/apps/production/src/analytics/analytics.controller.ts@@ -1296,10 +1296,12 @@ export class AnalyticsController {@Headers() headers,@Ip() reqIP,): Promise<any> {- const { 'user-agent': userAgent } = headers+ const { 'user-agent': userAgent, origin } = headersconst { pid } = logDTOconst ip = getIPFromHeaders(headers, true) || reqIP || ''+ await this.analyticsService.validateHeartbeat(logDTO, origin, ip)+const [, sessionID] = await this.analyticsService.isUnique(pid,userAgent,diff --git a/backend/apps/production/src/analytics/analytics.service.ts b/backend/apps/production/src/analytics/analytics.service.tsindex 08e72f723..3e94ed1ab 100644--- a/backend/apps/production/src/analytics/analytics.service.ts+++ b/backend/apps/production/src/analytics/analytics.service.ts@@ -518,6 +518,40 @@ export class AnalyticsService {return null}+ async validateHeartbeat(+ logDTO: PageviewsDTO,+ origin: string,+ ip?: string,+ ): Promise<string | null> {+ if (_isEmpty(logDTO)) {+ throw new BadRequestException('The request cannot be empty')+ }++ const { pid } = logDTO+ this.validatePID(pid)++ const project = await this.projectService.getRedisProject(pid)++ this.checkIpBlacklist(project, ip)++ if (!project.active) {+ throw new BadRequestException(+ 'Incoming analytics is disabled for this project',+ )+ }++ if (project.admin?.isAccountBillingSuspended) {+ throw new HttpException(+ 'The account that owns this site is currently suspended, this is because of a billing issue. This, and all other events, are NOT being tracked and saved on our side. Please log in to your account on Swetrix or contact our support to resolve the issue.',+ HttpStatus.PAYMENT_REQUIRED,+ )+ }++ this.checkOrigin(project, origin)++ return null+ }+getDataTypeColumns(dataType: DataType): string[] {if (dataType === DataType.ANALYTICS) {return TRAFFIC_COLUMNS