📈 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
Fix validation and update SQL queries
Yehor Dremliuhafaf903db2f20
diff --git a/apps/production/src/analytics/analytics.service.ts b/apps/production/src/analytics/analytics.service.tsindex 2de5d684b..d3b3bbc1d 100644--- a/apps/production/src/analytics/analytics.service.ts+++ b/apps/production/src/analytics/analytics.service.ts@@ -3705,6 +3705,8 @@ export class AnalyticsService {).join(' ')+ const metaKeysMapped = metaKeys.map(key => `'${key}'`).join(', ')+const query = `SELECTkey,@@ -3712,7 +3714,7 @@ export class AnalyticsService {avg(CASE ${casesAvg} ELSE 0 END) AS avgFROM customEVARRAY JOIN meta.key AS key, meta.value AS value- WHERE pid = {pid:String} AND key IN (${metaKeys.map(key => `'${key}'`).join(', ')})+ WHERE pid = {pid:String} AND key IN (${metaKeysMapped})GROUP BY key`diff --git a/apps/production/src/project/dto/create-project-view.dto.ts b/apps/production/src/project/dto/create-project-view.dto.tsindex 3cf832c2c..f6c9ddd5b 100644--- a/apps/production/src/project/dto/create-project-view.dto.ts+++ b/apps/production/src/project/dto/create-project-view.dto.ts@@ -13,6 +13,7 @@ import {ValidatorConstraint,ValidatorConstraintInterface,isISO31661Alpha2,+ IsUrl,} from 'class-validator'import { ApiProperty } from '@nestjs/swagger'@@ -137,9 +138,7 @@ export class CreateProjectViewDto {'Referrer (site from which the user came to the site using Swetrix)',nullable: true,})- @Matches(/^(https?:\/\/)?([a-zA-Z0-9.-]+)(:[0-9]{1,5})?(\/.*)?$/, {- message: 'Invalid referrer URL format',- })+ @IsUrl()@IsOptional()ref?: string@@ -173,14 +172,12 @@ export class CreateProjectViewDto {@MaxLength(100)@MinLength(1)@IsString()- @IsString()rg?: string@ApiProperty({ description: 'City (Berlin, London, etc.)', nullable: true })@MaxLength(100)@MinLength(1)@IsString()- @IsString()ct?: string@ApiProperty({ type: ProjectViewCustomEventDto, isArray: true })diff --git a/migrations/mysql/2024_07_08.sql b/migrations/mysql/2024_07_08.sqlindex ac969a963..6e00be020 100644--- a/migrations/mysql/2024_07_08.sql+++ b/migrations/mysql/2024_07_08.sql@@ -32,5 +32,5 @@ CREATE TABLE projects_views_custom_events (createdAt DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),updatedAt DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),FOREIGN KEY (viewId) REFERENCES projects_views(id) ON DELETE CASCADE-)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;