📈 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
Online users count: rely on hb, not sd
Blue Mousee2df5b6b2cdf
diff --git a/backend/apps/production/src/analytics/analytics.controller.ts b/backend/apps/production/src/analytics/analytics.controller.tsindex 7b749fafb..f64d85dda 100644--- a/backend/apps/production/src/analytics/analytics.controller.ts+++ b/backend/apps/production/src/analytics/analytics.controller.ts@@ -1082,7 +1082,7 @@ export class AnalyticsController {)await this.analyticsService.checkBillingAccess(pid)- const keys = await redis.keys(`sd:*:${pid}`)+ const keys = await redis.keys(`hb:*:${pid}`)if (_isEmpty(keys)) {return []}@@ -1303,19 +1303,15 @@ export class AnalyticsController {await this.analyticsService.validateHeartbeat(logDTO, origin, ip)- const [, sessionID] = await this.analyticsService.isUnique(- pid,- userAgent,- ip,- )+ const [, psid] = await this.analyticsService.isUnique(pid, userAgent, ip)await redis.set(- getHeartbeatKey(pid, sessionID),+ getHeartbeatKey(psid, pid),1,'EX',HEARTBEAT_SID_LIFE_TIME,)- await this.analyticsService.processInteractionSD(sessionID, pid)+ await this.analyticsService.processInteractionSD(psid, pid)}// Log pageview eventdiff --git a/backend/apps/production/src/analytics/analytics.service.ts b/backend/apps/production/src/analytics/analytics.service.tsindex 1ce83cfa1..c9a1863d6 100644--- a/backend/apps/production/src/analytics/analytics.service.ts+++ b/backend/apps/production/src/analytics/analytics.service.ts@@ -109,8 +109,8 @@ dayjs.extend(utc)dayjs.extend(dayjsTimezone)dayjs.extend(isSameOrBefore)-export const getHeartbeatKey = (pid: string, sessionID: string) =>- `hb:${pid}:${sessionID}`+export const getHeartbeatKey = (psid: string, pid: string) =>+ `hb:${psid}:${pid}`const getSessionDurationKey = (psid: string, pid: string) => `sd:${psid}:${pid}`@@ -3537,8 +3537,8 @@ export class AnalyticsService {}async getOnlineUserCount(pid: string): Promise<number> {- // @ts-ignore- return redis.countKeysByPattern(`hb:${pid}:*`)+ // @ts-expect-error+ return redis.countKeysByPattern(`hb:*:${pid}`)}async groupCustomEVByTimeBucket(@@ -4096,11 +4096,6 @@ export class AnalyticsService {}}- async getOnlineCountByProjectId(projectId: string) {- // @ts-ignore- return redis.countKeysByPattern(`hb:${projectId}:*`)- }-checkIfPerfMeasureIsValid(measure: PerfMeasure) {const validMeasures = ['average', 'median', 'p95', 'quantiles']diff --git a/backend/apps/production/src/integrations/telegram/scene/projects.scene.ts b/backend/apps/production/src/integrations/telegram/scene/projects.scene.tsindex 840ea644f..814c5e0b1 100644--- a/backend/apps/production/src/integrations/telegram/scene/projects.scene.ts+++ b/backend/apps/production/src/integrations/telegram/scene/projects.scene.ts@@ -75,7 +75,7 @@ export class ProjectsScene {await context.scene.reenter()}- const onlineCount = await this.analyticsService.getOnlineCountByProjectId(+ const onlineCount = await this.analyticsService.getOnlineUserCount(project.id,)const stats = await this.analyticsService.getAnalyticsSummary(diff --git a/backend/apps/selfhosted/src/analytics/analytics.controller.ts b/backend/apps/selfhosted/src/analytics/analytics.controller.tsindex ae5ccc1bd..a9f73b63c 100644--- a/backend/apps/selfhosted/src/analytics/analytics.controller.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.controller.ts@@ -880,7 +880,7 @@ export class AnalyticsController {headers['x-password'],)- const keys = await redis.keys(`sd:*:${pid}`)+ const keys = await redis.keys(`hb:*:${pid}`)if (_isEmpty(keys)) {return []}@@ -1016,19 +1016,15 @@ export class AnalyticsController {await this.analyticsService.validateHeartbeat(logDTO, origin, ip)- const [, sessionID] = await this.analyticsService.isUnique(- pid,- userAgent,- ip,- )+ const [, psid] = await this.analyticsService.isUnique(pid, userAgent, ip)await redis.set(- getHeartbeatKey(pid, sessionID),+ getHeartbeatKey(psid, pid),1,'EX',HEARTBEAT_SID_LIFE_TIME,)- await this.analyticsService.processInteractionSD(sessionID, pid)+ await this.analyticsService.processInteractionSD(psid, pid)}// Log pageview eventdiff --git a/backend/apps/selfhosted/src/analytics/analytics.service.ts b/backend/apps/selfhosted/src/analytics/analytics.service.tsindex afe2db70c..103acba30 100644--- a/backend/apps/selfhosted/src/analytics/analytics.service.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.service.ts@@ -98,8 +98,8 @@ dayjs.extend(utc)dayjs.extend(dayjsTimezone)dayjs.extend(isSameOrBefore)-export const getHeartbeatKey = (pid: string, sessionID: string) =>- `hb:${pid}:${sessionID}`+export const getHeartbeatKey = (psid: string, pid: string) =>+ `hb:${psid}:${pid}`const getSessionDurationKey = (psid: string, pid: string) => `sd:${psid}:${pid}`@@ -2917,8 +2917,8 @@ export class AnalyticsService {}async getOnlineUserCount(pid: string): Promise<number> {- // @ts-ignore- return redis.countKeysByPattern(`hb:${pid}:*`)+ // @ts-expect-error+ return redis.countKeysByPattern(`hb:*:${pid}`)}async groupCustomEVByTimeBucket(@@ -3476,11 +3476,6 @@ export class AnalyticsService {}}- async getOnlineCountByProjectId(projectId: string) {- // @ts-ignore- return redis.countKeysByPattern(`hb:${projectId}:*`)- }-checkIfPerfMeasureIsValid(measure: PerfMeasure) {const validMeasures = ['average', 'median', 'p95', 'quantiles']