📈 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
review fixes
Blue Mouse312cdea81205
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.tsindex 692f7acec..546061f05 100644--- a/backend/apps/cloud/src/analytics/analytics.service.ts+++ b/backend/apps/cloud/src/analytics/analytics.service.ts@@ -2469,13 +2469,12 @@ export class AnalyticsService {generateAnalyticsAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,mode: ChartRenderMode,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const baseQuery = `SELECT@@ -2487,7 +2486,7 @@ export class AnalyticsService {SELECTpid,psid,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM analyticsPREWHERE pid = {pid:FixedString(12)}WHERE created BETWEEN ${tzFromDate} AND ${tzToDate}@@ -2523,12 +2522,11 @@ export class AnalyticsService {generateSessionAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const baseQuery = `SELECT@@ -2536,7 +2534,7 @@ export class AnalyticsService {count() as pageviewsFROM (SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM analyticsPREWHERE pid = {pid:FixedString(12)}WHERE created BETWEEN ${tzFromDate} AND ${tzToDate}@@ -2552,12 +2550,11 @@ export class AnalyticsService {generateSessionCustomEventsAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`return `SELECT@@ -2565,7 +2562,7 @@ export class AnalyticsService {count() as customEventsCountFROM (SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM customEVPREWHERE pid = {pid:FixedString(12)}WHERE created BETWEEN ${tzFromDate} AND ${tzToDate}@@ -2579,12 +2576,11 @@ export class AnalyticsService {generateSessionErrorsAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`return `SELECT@@ -2592,7 +2588,7 @@ export class AnalyticsService {count() as errorsCountFROM (SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM errorsPREWHERE pid = {pid:FixedString(12)}WHERE created BETWEEN ${tzFromDate} AND ${tzToDate}@@ -2606,13 +2602,12 @@ export class AnalyticsService {generateCustomEventsAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,mode: ChartRenderMode,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const baseQuery = `SELECT@@ -2620,7 +2615,7 @@ export class AnalyticsService {count() as countFROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM customEVWHERE pid = {pid:FixedString(12)}AND created BETWEEN ${tzFromDate} AND ${tzToDate}@@ -2645,13 +2640,12 @@ export class AnalyticsService {generatePerformanceAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,measure: PerfMeasure,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const cols = ['dns', 'tls', 'conn', 'response', 'render', 'domLoad', 'ttfb']@@ -2665,7 +2659,7 @@ export class AnalyticsService {${columnSelectors}FROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM performanceWHEREpid = {pid:FixedString(12)}@@ -2680,12 +2674,11 @@ export class AnalyticsService {generatePerformanceQuantilesQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const cols = ['dns', 'tls', 'conn', 'response', 'render', 'domLoad', 'ttfb']@@ -2699,7 +2692,7 @@ export class AnalyticsService {${columnSelectors}FROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM performanceWHEREpid = {pid:FixedString(12)}@@ -2714,13 +2707,12 @@ export class AnalyticsService {generateCaptchaAggregationQuery(timeBucket: TimeBucketType,filtersQuery: string,- safeTimezone: string,mode: ChartRenderMode,): string {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const baseQuery = `SELECT@@ -2728,7 +2720,7 @@ export class AnalyticsService {count() as countFROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM captchaWHEREpid = {pid:FixedString(12)}@@ -2953,14 +2945,13 @@ export class AnalyticsService {const query = this.generateCustomEventsAggregationQuery(timeBucket,filtersQuery,- safeTimezone,mode,)const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json<TrafficCEFilterCHResponse>())@@ -2982,14 +2973,13 @@ export class AnalyticsService {const query = this.generateAnalyticsAggregationQuery(timeBucket,filtersQuery,- safeTimezone,mode,)const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json<TrafficCHResponse>())@@ -3086,36 +3076,35 @@ export class AnalyticsService {const pageviewsQuery = this.generateSessionAggregationQuery(timeBucket,filtersQuery,- safeTimezone,)const customEventsQuery = this.generateSessionCustomEventsAggregationQuery(timeBucket,filtersQuery,- safeTimezone,)const errorsQuery = this.generateSessionErrorsAggregationQuery(timeBucket,filtersQuery,- safeTimezone,)+ const queryParams = { ...paramsData.params, timezone: safeTimezone }+const [pageviewsData, customEventsData, errorsData] = await Promise.all([clickhouse.query({query: pageviewsQuery,- query_params: paramsData.params,+ query_params: queryParams,}).then(resultSet => resultSet.json<any>()),clickhouse.query({query: customEventsQuery,- query_params: paramsData.params,+ query_params: queryParams,}).then(resultSet => resultSet.json<any>()),clickhouse.query({query: errorsQuery,- query_params: paramsData.params,+ query_params: queryParams,}).then(resultSet => resultSet.json<any>()),])@@ -3259,14 +3248,13 @@ export class AnalyticsService {const query = this.generateCaptchaAggregationQuery(timeBucket,filtersQuery,- safeTimezone,mode,)const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json<TrafficCEFilterCHResponse>())const { count } = this.extractCaptchaChartData(data, xShifted)@@ -3434,13 +3422,12 @@ export class AnalyticsService {const query = this.generatePerformanceQuantilesQuery(timeBucket,filtersQuery,- safeTimezone,)const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json())@@ -3453,14 +3440,13 @@ export class AnalyticsService {const query = this.generatePerformanceAggregationQuery(timeBucket,filtersQuery,- safeTimezone,measure,)const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json<PerformanceCHResponse>())@@ -3840,8 +3826,8 @@ export class AnalyticsService {const timeBucketFunc = timeBucketConversion[timeBucket]const [selector, groupBy] = this.getGroupSubquery(timeBucket)- const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), '${safeTimezone}')`- const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), '${safeTimezone}')`+ const tzFromDate = `toTimeZone(parseDateTimeBestEffort({groupFrom:String}), {timezone:String})`+ const tzToDate = `toTimeZone(parseDateTimeBestEffort({groupTo:String}), {timezone:String})`const query = `SELECT@@ -3850,7 +3836,7 @@ export class AnalyticsService {count() as countFROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM customEVWHEREpid = {pid:FixedString(12)}@@ -3864,7 +3850,7 @@ export class AnalyticsService {const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json<CustomsCHAggregatedResponse>())@@ -3916,7 +3902,7 @@ export class AnalyticsService {SELECT'pageview' AS type,pg AS value,- toTimeZone(analytics.created, '${safeTimezone}') AS created,+ toTimeZone(analytics.created, {timezone:String}) AS created,pid,psid,groupArrayIf(tuple(meta.key, meta.value), notEmpty(meta.key) AND notEmpty(meta.value)) AS metadata@@ -3933,7 +3919,7 @@ export class AnalyticsService {SELECT'event' AS type,ev AS value,- toTimeZone(customEV.created, '${safeTimezone}') AS created,+ toTimeZone(customEV.created, {timezone:String}) AS created,pid,psid,groupArrayIf(tuple(meta.key, meta.value), notEmpty(meta.key) AND notEmpty(meta.value)) AS metadata@@ -3950,7 +3936,7 @@ export class AnalyticsService {SELECT'error' AS type,errors.name AS value,- toTimeZone(errors.created, '${safeTimezone}') AS created,+ toTimeZone(errors.created, {timezone:String}) AS created,pid,psid,[@@ -4000,6 +3986,7 @@ export class AnalyticsService {params: {pid,psid,+ timezone: safeTimezone,},}@@ -4135,7 +4122,7 @@ export class AnalyticsService {${primaryEventsTable}.cc,${primaryEventsTable}.os,${primaryEventsTable}.br,- toTimeZone(${primaryEventsTable}.created, '${safeTimezone}') AS created_for_grouping+ toTimeZone(${primaryEventsTable}.created, {timezone:String}) AS created_for_groupingFROM ${primaryEventsTable}WHERE${primaryEventsTable}.pid = {pid:FixedString(12)}@@ -4222,7 +4209,7 @@ export class AnalyticsService {const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json())@@ -4514,7 +4501,7 @@ export class AnalyticsService {const queryPageviews = `SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) AS time,+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) AS time,count() AS countFROM analyticsWHERE pid = {pid:FixedString(12)}@@ -4526,7 +4513,7 @@ export class AnalyticsService {const queryEvents = `SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) AS time,+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) AS time,count() AS countFROM customEVWHERE pid = {pid:FixedString(12)}@@ -4538,7 +4525,7 @@ export class AnalyticsService {const queryErrors = `SELECT- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) AS time,+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) AS time,count() AS countFROM errorsWHERE pid = {pid:FixedString(12)}@@ -4548,7 +4535,7 @@ export class AnalyticsService {ORDER BY time ASC`- const params = { pid, profileId, from, to }+ const params = { pid, profileId, from, to, timezone: safeTimezone }const [pageviewsResult, eventsResult, errorsResult] = await Promise.all([clickhouse@@ -4620,8 +4607,8 @@ export class AnalyticsService {any(cc) AS cc,any(os) AS os,any(br) AS br,- min(toTimeZone(created, '${safeTimezone}')) AS sessionStart,- max(toTimeZone(created, '${safeTimezone}')) AS lastActivity+ min(toTimeZone(created, {timezone:String})) AS sessionStart,+ max(toTimeZone(created, {timezone:String})) AS lastActivityFROM analyticsWHERE pid = {pid:FixedString(12)}AND profileId = {profileId:String}@@ -4702,7 +4689,12 @@ export class AnalyticsService {const { data } = await clickhouse.query({query,- query_params: { pid, profileId, ...paramsData.params },+ query_params: {+ pid,+ profileId,+ ...paramsData.params,+ timezone: safeTimezone,+ },}).then(resultSet => resultSet.json())@@ -4737,7 +4729,7 @@ export class AnalyticsService {max(created) as last_seen,status.statusFROM (- SELECT eid, name, message, filename, toTimeZone(errors.created, '${safeTimezone}') AS created+ SELECT eid, name, message, filename, toTimeZone(errors.created, {timezone:String}) AS createdFROM errorsWHERE pid = {pid:FixedString(12)}AND errors.created BETWEEN {groupFrom:String} AND {groupTo:String}@@ -4765,7 +4757,7 @@ export class AnalyticsService {const { data } = await clickhouse.query({query,- query_params: paramsData.params,+ query_params: { ...paramsData.params, timezone: safeTimezone },}).then(resultSet => resultSet.json())diff --git a/backend/apps/cloud/src/goal/goal.controller.ts b/backend/apps/cloud/src/goal/goal.controller.tsindex 2ac75b692..cee54b458 100644--- a/backend/apps/cloud/src/goal/goal.controller.ts+++ b/backend/apps/cloud/src/goal/goal.controller.ts@@ -207,7 +207,7 @@ export class GoalController {pid: goalDto.pid,}} catch (reason) {- console.error('Error while creating goal', reason)+ this.logger.error({ reason }, 'Error while creating goal')throw new BadRequestException('Error occurred while creating goal')}}@@ -300,7 +300,10 @@ export class GoalController {}} else {// Regex match- params.goalValue = goal.value || ''+ if (!goal.value) {+ return { condition: '0', params }+ }+ params.goalValue = goal.valuereturn { condition: `match(ev, {goalValue:String})`, params }}} else {@@ -316,7 +319,10 @@ export class GoalController {}} else {// Regex match- params.goalValue = goal.value || ''+ if (!goal.value) {+ return { condition: '0', params }+ }+ params.goalValue = goal.valuereturn { condition: `match(pg, {goalValue:String})`, params }}}@@ -567,7 +573,7 @@ export class GoalController {@Query('period') period: string,@Query('from') from?: string,@Query('to') to?: string,- @Query('timeBucket') timeBucket: string = 'day',+ @Query('timeBucket') timeBucket?: string,@Query('timezone') timezone?: string,) {this.logger.log(@@ -605,7 +611,8 @@ export class GoalController {)const table = goal.type === GoalType.CUSTOM_EVENT ? 'customEV' : 'analytics'- const timeBucketFunc = timeBucketConversion[timeBucket] || 'toStartOfDay'+ const timeBucketFunc =+ timeBucketConversion[resolvedTimeBucket] || 'toStartOfDay'const [selector, groupBy] = this.getGroupSubquery(resolvedTimeBucket)const { condition: matchCondition, params: matchParams } =@@ -620,7 +627,7 @@ export class GoalController {uniqExact(psid) as uniqueSessionsFROM (SELECT *,- ${timeBucketFunc}(toTimeZone(created, '${safeTimezone}')) as tz_created+ ${timeBucketFunc}(toTimeZone(created, {timezone:String})) as tz_createdFROM ${table}WHEREpid = {pid:FixedString(12)}@@ -636,6 +643,7 @@ export class GoalController {pid: goal.project.id,groupFrom: groupFromUTC,groupTo: groupToUTC,+ timezone: safeTimezone,...matchParams,...metaParams,}diff --git a/web/app/pages/Project/Goals/View/GoalsView.tsx b/web/app/pages/Project/Goals/View/GoalsView.tsxindex 7b985e226..3f04d6d6a 100644--- a/web/app/pages/Project/Goals/View/GoalsView.tsx+++ b/web/app/pages/Project/Goals/View/GoalsView.tsx@@ -58,8 +58,14 @@ import GoalSettingsModal from './GoalSettingsModal'// Calculate optimal Y axis ticksconst calculateOptimalTicks = (data: number[], targetCount: number = 6): number[] => {- const min = Math.min(...data.filter((n) => n !== undefined && n !== null))- const max = Math.max(...data.filter((n) => n !== undefined && n !== null))+ const validData = data.filter((n) => n !== undefined && n !== null && Number.isFinite(n))++ if (validData.length === 0) {+ return [0, 1]+ }++ const min = Math.min(...validData)+ const max = Math.max(...validData)if (min === max) {return max === 0 ? [0, 1] : [0, max * 1.2]@@ -466,7 +472,7 @@ const GoalsView = ({ period, from = '', to = '', timezone }: GoalsViewProps) =>setGoals(result.results)setTotal(result.total)} catch (reason: any) {- setError(reason)+ setError(reason?.message || reason?.toString() || 'Unknown error')} finally {isLoadingRef.current = falsesetIsLoading(false)