📈 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
Added custom event selection
Yevhenii Kulisidi95834b3f0c5d
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex 6cadd838f..b79d40c6c 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -65,6 +65,7 @@ import {} from '../common/constants'import { BotDetection } from '../common/decorators/bot-detection.decorator'import { BotDetectionGuard } from '../common/guards/bot-detection.guard'+import { GetCustomEventsDto } from './dto/get-custom-events.dto'// eslint-disable-next-line @typescript-eslint/no-var-requiresconst mysql = require('mysql2')@@ -1064,7 +1065,7 @@ export class AnalyticsController {@Get('custom-events')@Auth([], true, true)async getCustomEvents(- @Query() data: AnalyticsGET_DTO,+ @Query() data: GetCustomEventsDto,@CurrentUserId() uid: string,): Promise<any> {const {@@ -1075,6 +1076,7 @@ export class AnalyticsController {to,filters,timezone = DEFAULT_TIMEZONE,+ customEvents,} = datathis.analyticsService.validatePID(pid)@@ -1206,7 +1208,7 @@ export class AnalyticsController {const customEventsName = Object.keys(customs)- const result = await this.analyticsService.groupCustomEVByTimeBucket(+ const result: any = await this.analyticsService.groupCustomEVByTimeBucket(timeBucket,groupFrom,groupTo,@@ -1217,6 +1219,25 @@ export class AnalyticsController {customEventsName,)+ let customEventss = customEvents++ if (filters) {+ try {+ customEventss = JSON.parse(customEvents)+ // eslint-disable-next-line no-empty+ } catch {}+ }++ if (customEventss.length > 0) {+ for (const key in result.chart.events) {+ if (!customEventss.includes(key)) {+ delete result.chart.events[key]+ }+ }+ } else {+ result.chart = {}+ }+return {...result,appliedFilters,diff --git a/src/analytics/dto/get-custom-events.dto.ts b/src/analytics/dto/get-custom-events.dto.tsnew file mode 100644index 000000000..76532db9d--- /dev/null+++ b/src/analytics/dto/get-custom-events.dto.ts@@ -0,0 +1,14 @@+import { PickType } from '@nestjs/swagger'+import { AnalyticsGET_DTO } from './getData.dto'++export class GetCustomEventsDto extends PickType(AnalyticsGET_DTO, [+ 'pid',+ 'period',+ 'timeBucket',+ 'from',+ 'to',+ 'filters',+ 'timezone',+] as const) {+ customEvents: string+}