📈 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
lint:fix
Blue Mouse5b56da45fc73
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex 05b43f767..469a9dfbf 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -286,15 +286,14 @@ export class AnalyticsController {)const safeTimezone = this.analyticsService.getSafeTimezone(timezone)- const {- groupFrom, groupTo, groupFromUTC, groupToUTC,- } = this.analyticsService.getGroupFromTo(- from,- to,- timeBucket,- period,- safeTimezone,- )+ const { groupFrom, groupTo, groupFromUTC, groupToUTC } =+ this.analyticsService.getGroupFromTo(+ from,+ to,+ timeBucket,+ period,+ safeTimezone,+ )await this.analyticsService.checkProjectAccess(pid, uid)let queryCustoms = `SELECT ev, count() FROM customEV WHERE pid = {pid:FixedString(12)} ${filtersQuery} AND created BETWEEN {groupFrom:String} AND {groupTo:String} GROUP BY ev`@@ -463,8 +462,8 @@ export class AnalyticsController {this.analyticsService.validateTimebucket(timeBucket)const [filtersQuery, filtersParams, parsedFilters] =this.analyticsService.getFiltersQuery(filters, DataType.PERFORMANCE)-- const safeTimezone = this.analyticsService.getSafeTimezone(timezone)++ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,@@ -525,8 +524,8 @@ export class AnalyticsController {this.analyticsService.validateTimebucket(timeBucket)const [filtersQuery, filtersParams, parsedFilters] =this.analyticsService.getFiltersQuery(filters, DataType.PERFORMANCE)-- const safeTimezone = this.analyticsService.getSafeTimezone(timezone)++ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,@@ -575,9 +574,7 @@ export class AnalyticsController {@Query() data: GetUserFlowDTO,@CurrentUserId() uid: string,): Promise<IUserFlow | { appliedFilters: any[] }> {- const {- pid, period, from, to, timezone = DEFAULT_TIMEZONE, filters,- } = data+ const { pid, period, from, to, timezone = DEFAULT_TIMEZONE, filters } = datathis.analyticsService.validatePID(pid)if (!_isEmpty(period)) {@@ -1049,7 +1046,6 @@ export class AnalyticsController {this.analyticsService.getFiltersQuery(filters, DataType.ANALYTICS)await this.analyticsService.checkProjectAccess(pid, uid)-const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex 173d5ca99..70f331f7a 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -124,11 +124,7 @@ const validTimebuckets = [const timeBucketToDays = [{lt: 7,- tb: [- TimeBucketType.HOUR,- TimeBucketType.DAY,- TimeBucketType.MONTH,- ],+ tb: [TimeBucketType.HOUR, TimeBucketType.DAY, TimeBucketType.MONTH],}, // 7 days{lt: 28,@@ -384,9 +380,11 @@ export class AnalyticsService {): IGetGroupFromTo {let groupFrom: dayjs.Dayjslet groupTo: dayjs.Dayjs- let formatFrom = 'YYYY-MM-DD HH:mm:ss'- let formatTo = 'YYYY-MM-DD HH:mm:ss'- const djsNow = _includes(GMT_0_TIMEZONES, safeTimezone) ? dayjs.utc() : dayjs().tz(safeTimezone)+ const formatFrom = 'YYYY-MM-DD HH:mm:ss'+ const formatTo = 'YYYY-MM-DD HH:mm:ss'+ const djsNow = _includes(GMT_0_TIMEZONES, safeTimezone)+ ? dayjs.utc()+ : dayjs().tz(safeTimezone)if (!_isEmpty(from) && !_isEmpty(to)) {if (!isValidDate(from)) {@@ -423,12 +421,8 @@ export class AnalyticsService {groupFrom = djsNow.startOf('d')groupTo = djsNow} else if (period === 'yesterday') {- groupFrom = djsNow- .subtract(1, 'day')- .startOf('d')- groupTo = djsNow- .subtract(1, 'day')- .endOf('d')+ groupFrom = djsNow.subtract(1, 'day').startOf('d')+ groupTo = djsNow.subtract(1, 'day').endOf('d')} else {// if (period === '1d') {// groupFrom = dayjs.utc()@@ -446,7 +440,11 @@ export class AnalyticsService {}if (!_isEmpty(timeBucket)) {- checkIfTBAllowed(timeBucket, groupFrom.format(formatFrom), groupTo.format(formatTo))+ checkIfTBAllowed(+ timeBucket,+ groupFrom.format(formatFrom),+ groupTo.format(formatTo),+ )}} else {throw new BadRequestException(@@ -841,8 +839,12 @@ export class AnalyticsService {to: string,safeTimezone: string,): IGenerateXAxis {- const iterateTo = _includes(GMT_0_TIMEZONES, safeTimezone) ? dayjs.utc(to) : dayjs.tz(to, safeTimezone)- let djsFrom = _includes(GMT_0_TIMEZONES, safeTimezone) ? dayjs.utc(from) : dayjs.tz(from, safeTimezone)+ const iterateTo = _includes(GMT_0_TIMEZONES, safeTimezone)+ ? dayjs.utc(to)+ : dayjs.tz(to, safeTimezone)+ let djsFrom = _includes(GMT_0_TIMEZONES, safeTimezone)+ ? dayjs.utc(from)+ : dayjs.tz(from, safeTimezone)let format@@ -892,11 +894,7 @@ export class AnalyticsService {checkTimebucket(timeBucket: TimeBucketType): void {const isValid = _includes(- [- TimeBucketType.HOUR,- TimeBucketType.DAY,- TimeBucketType.MONTH,- ],+ [TimeBucketType.HOUR, TimeBucketType.DAY, TimeBucketType.MONTH],timeBucket,)@@ -1054,9 +1052,7 @@ export class AnalyticsService {SELECT *,${timeBucketFunc}(created) as tz_createdFROM customEV- WHERE ${- paramsData.params.ev_exclusive ? 'NOT' : ''- } ev = {ev:String}+ WHERE ${paramsData.params.ev_exclusive ? 'NOT' : ''} ev = {ev:String}AND pid = {pid:FixedString(12)}AND created BETWEEN {groupFrom:String} AND {groupTo:String}${filtersQuery}@@ -1214,7 +1210,12 @@ export class AnalyticsService {? 0: await this.calculateAverageSessionDuration(subQuery, paramsData)- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)+ const { x, xShifted } = this.generateXAxis(+ timeBucket,+ from,+ to,+ safeTimezone,+ )if (customEVFilterApplied) {const query = this.generateCustomEventsAggregationQuery(@@ -1228,8 +1229,7 @@ export class AnalyticsService {)const uniques =- this.extractCustomEventsChartData(result, x)?._unknown_event ||- []+ this.extractCustomEventsChartData(result, x)?._unknown_event || []const sdur = Array(_size(x)).fill(0)@@ -1392,7 +1392,12 @@ export class AnalyticsService {paramsData: object,safeTimezone: string,) {- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)+ const { x, xShifted } = this.generateXAxis(+ timeBucket,+ from,+ to,+ safeTimezone,+ )const query = this.generatePerformanceAggregationQuery(timeBucket,@@ -1490,7 +1495,12 @@ export class AnalyticsService {paramsData: object,safeTimezone: string,): Promise<object | void> {- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)+ const { x, xShifted } = this.generateXAxis(+ timeBucket,+ from,+ to,+ safeTimezone,+ )const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)