📈 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
always pass safeTimezone from controller to the service
Blue Mouse5d6257d1a762
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex 83555cbbb..05b43f767 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -284,7 +284,7 @@ export class AnalyticsController {filters,isCaptcha ? DataType.CAPTCHA : DataType.ANALYTICS,)-+const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const {groupFrom, groupTo, groupFromUTC, groupToUTC,@@ -293,7 +293,7 @@ export class AnalyticsController {to,timeBucket,period,- timezone,+ safeTimezone,)await this.analyticsService.checkProjectAccess(pid, uid)@@ -392,12 +392,14 @@ export class AnalyticsController {this.analyticsService.validateTimebucket(timeBucket)const [filtersQuery, filtersParams, parsedFilters] =this.analyticsService.getFiltersQuery(filters, DataType.ANALYTICS)++ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,timeBucket,period,- timezone,+ safeTimezone,)await this.analyticsService.checkProjectAccess(pid, uid)@@ -427,7 +429,7 @@ export class AnalyticsController {subQuery,filtersQuery,paramsData,- timezone,+ safeTimezone,customEVFilterApplied,)@@ -461,12 +463,14 @@ export class AnalyticsController {this.analyticsService.validateTimebucket(timeBucket)const [filtersQuery, filtersParams, parsedFilters] =this.analyticsService.getFiltersQuery(filters, DataType.PERFORMANCE)++ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,timeBucket,period,- timezone,+ safeTimezone,)await this.analyticsService.checkProjectAccess(pid, uid)@@ -488,7 +492,7 @@ export class AnalyticsController {subQuery,filtersQuery,paramsData,- timezone,+ safeTimezone,)return {@@ -521,12 +525,14 @@ export class AnalyticsController {this.analyticsService.validateTimebucket(timeBucket)const [filtersQuery, filtersParams, parsedFilters] =this.analyticsService.getFiltersQuery(filters, DataType.PERFORMANCE)++ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,timeBucket,period,- timezone,+ safeTimezone,)await this.analyticsService.checkProjectAccess(pid, uid)@@ -545,7 +551,7 @@ export class AnalyticsController {to,filtersQuery,paramsData,- timezone,+ safeTimezone,)return {@@ -580,12 +586,13 @@ export class AnalyticsController {await this.analyticsService.checkProjectAccess(pid, uid)+ const safeTimezone = this.analyticsService.getSafeTimezone(timezone)const { groupFrom, groupTo } = this.analyticsService.getGroupFromTo(from,to,null,period,- timezone,+ safeTimezone,)const [filtersQuery, filtersParams, parsedFilters] =@@ -1042,12 +1049,14 @@ 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,to,timeBucket,period,- timezone,+ safeTimezone,)const paramsData = {@@ -1065,7 +1074,7 @@ export class AnalyticsController {groupTo,filtersQuery,paramsData,- timezone,+ safeTimezone,)let customEventss = customEventsdiff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex 25133a56a..6228a411d 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -380,14 +380,12 @@ export class AnalyticsService {to: string,timeBucket: TimeBucketType | null,period: string,- timezone: string,+ safeTimezone: string,): IGetGroupFromTo {let groupFrom: dayjs.Dayjslet groupTo: dayjs.Dayjslet formatFrom = 'YYYY-MM-DD HH:mm:ss'let formatTo = 'YYYY-MM-DD HH:mm:ss'- const safeTimezone = this.getSafeTimezone(timezone)-const djsNow = _includes(GMT_0_TIMEZONES, safeTimezone) ? dayjs.utc() : dayjs().tz(safeTimezone)if (!_isEmpty(from) && !_isEmpty(to)) {@@ -841,10 +839,8 @@ export class AnalyticsService {timeBucket: TimeBucketType,from: string, // timezone is already applied to the from and to parametersto: string,- timezone: string,+ safeTimezone: string,): IGenerateXAxis {- const safeTimezone = this.getSafeTimezone(timezone)-console.log('GEN X AXIS:', from, ' -> ', to)const iterateTo = _includes(GMT_0_TIMEZONES, safeTimezone) ? dayjs.utc(to) : dayjs.tz(to, safeTimezone)@@ -1138,7 +1134,7 @@ export class AnalyticsService {subQuery: string,filtersQuery: string,paramsData: any,- timezone: string,+ safeTimezone: string,customEVFilterApplied: boolean,parsedFilters: Array<{ [key: string]: string }>,): Promise<object | void> {@@ -1172,7 +1168,7 @@ export class AnalyticsService {subQuery,filtersQuery,paramsData,- timezone,+ safeTimezone,customEVFilterApplied,)@@ -1216,14 +1212,14 @@ export class AnalyticsService {subQuery: string,filtersQuery: string,paramsData: any,- timezone: string,+ safeTimezone: string,customEVFilterApplied: boolean,): Promise<object | void> {const avgSdur = customEVFilterApplied? 0: await this.calculateAverageSessionDuration(subQuery, paramsData)- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, timezone)+ const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)if (customEVFilterApplied) {const query = this.generateCustomEventsAggregationQuery(@@ -1302,7 +1298,7 @@ export class AnalyticsService {subQuery: string,filtersQuery: string,paramsData: object,- timezone: string,+ safeTimezone: string,): Promise<object | void> {let params: unknown = {}let chart: unknown = {}@@ -1332,7 +1328,7 @@ export class AnalyticsService {timeBucket,from,to,- timezone,+ safeTimezone,)const query = this.generateCaptchaAggregationQuery(@@ -1402,9 +1398,9 @@ export class AnalyticsService {to: string,filtersQuery: string,paramsData: object,- timezone: string,+ safeTimezone: string,) {- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, timezone)+ const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)const query = this.generatePerformanceAggregationQuery(timeBucket,@@ -1428,7 +1424,7 @@ export class AnalyticsService {subQuery: string,filtersQuery: string,paramsData: object,- timezone: string,+ safeTimezone: string,): Promise<object | void> {let params: unknown = {}let chart: unknown = {}@@ -1460,7 +1456,7 @@ export class AnalyticsService {to,filtersQuery,paramsData,- timezone,+ safeTimezone,)})(),]@@ -1500,15 +1496,12 @@ export class AnalyticsService {to: string,filtersQuery: string,paramsData: object,- timezone: string,+ safeTimezone: string,): Promise<object | void> {- const safeTimezone = this.getSafeTimezone(timezone)- const { x, xShifted } = this.generateXAxis(timeBucket, from, to, timezone)+ const { x, xShifted } = this.generateXAxis(timeBucket, from, to, safeTimezone)const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}, 'UTC'), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}, 'UTC'), '${safeTimezone}')`const query = `SELECT@@ -1517,12 +1510,15 @@ export class AnalyticsService {count() as countFROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(created) as tz_createdFROM customEV- WHERE pid = {pid:FixedString(12)} AND created BETWEEN ${tzFromDate} AND ${tzToDate} ${filtersQuery}+ WHERE+ pid = {pid:FixedString(12)}+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}+ ${filtersQuery}) as subqueryGROUP BY ${groupBy}, ev- ORDER BY ${groupBy};+ ORDER BY ${groupBy}`const result = <Array<CustomsCHAggregatedResponse>>(