Skip to content

📈 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!

added an ability to grab chart only related data for performance

Blue Mouse734a3ce3bcf0
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.ts
index 087293b12..224644d37 100644
--- a/src/analytics/analytics.controller.ts
+++ b/src/analytics/analytics.controller.ts
@@ -523,6 +523,74 @@ export class AnalyticsController {
}
}
+ @Get('performance/chart')
+ @Auth([], true, true)
+ async getPerfChartData(
+ @Query() data: AnalyticsGET_DTO,
+ @CurrentUserId() uid: string,
+ ): Promise<any> {
+ const {
+ pid,
+ period,
+ timeBucket,
+ from,
+ to,
+ filters,
+ timezone = DEFAULT_TIMEZONE,
+ } = data
+ this.analyticsService.validatePID(pid)
+
+ if (!_isEmpty(period)) {
+ this.analyticsService.validatePeriod(period)
+ }
+
+ this.analyticsService.validateTimebucket(timeBucket)
+ const [filtersQuery, filtersParams] = this.analyticsService.getFiltersQuery(
+ filters,
+ DataType.PERFORMANCE,
+ )
+ const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(
+ from,
+ to,
+ timeBucket,
+ period,
+ timezone,
+ )
+ await this.analyticsService.checkProjectAccess(pid, uid)
+
+ const paramsData = {
+ params: {
+ pid,
+ groupFrom,
+ groupTo,
+ ...filtersParams,
+ },
+ }
+
+ const chart = await this.analyticsService.getPerfChartData(
+ timeBucket,
+ from,
+ to,
+ filtersQuery,
+ paramsData,
+ timezone,
+ )
+
+ let appliedFilters = filters
+
+ if (filters) {
+ try {
+ appliedFilters = JSON.parse(filters)
+ // eslint-disable-next-line no-empty
+ } catch {}
+ }
+
+ return {
+ chart,
+ appliedFilters,
+ }
+ }
+
@Get('captcha')
@Auth([], true, true)
async getCaptchaData(
diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.ts
index 00cdbf460..772a538fb 100644
--- a/src/analytics/analytics.service.ts
+++ b/src/analytics/analytics.service.ts
@@ -1431,6 +1431,34 @@ export class AnalyticsService {
}
}
+ async getPerfChartData(
+ timeBucket: TimeBucketType,
+ from: string,
+ to: string,
+ filtersQuery: string,
+ paramsData: object,
+ timezone: string,
+ ) {
+ const x = this.generateXAxis(timeBucket, from, to)
+
+ const query = this.generatePerformanceAggregationQuery(
+ timezone,
+ timeBucket,
+ filtersQuery,
+ )
+
+ const result = <Array<PerformanceCHResponse>>(
+ await clickhouse.query(query, paramsData).toPromise()
+ )
+
+ // x = this.updateXAxisTimezone(x, timezone, timeBucket)
+
+ return {
+ x,
+ ...this.extractPerformanceChartData(result, x),
+ }
+ }
+
async groupPerfByTimeBucket(
timeBucket: TimeBucketType,
from: string,
@@ -1464,24 +1492,14 @@ export class AnalyticsService {
// Getting chart data
(async () => {
- const x = this.generateXAxis(timeBucket, from, to)
-
- const query = this.generatePerformanceAggregationQuery(
- timezone,
+ chart = await this.getPerfChartData(
timeBucket,
+ from,
+ to,
filtersQuery,
+ paramsData,
+ timezone,
)
-
- const result = <Array<PerformanceCHResponse>>(
- await clickhouse.query(query, paramsData).toPromise()
- )
-
- // x = this.updateXAxisTimezone(x, timezone, timeBucket)
-
- chart = {
- x,
- ...this.extractPerformanceChartData(result, x),
- }
})(),
]