📈 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
Replace duplicate hb:* redis key with an existing sd:*
Blue Mouse31f15ecc8d27
diff --git a/backend/apps/production/src/analytics/analytics.controller.ts b/backend/apps/production/src/analytics/analytics.controller.tsindex 686a8304f..0ee13bdd6 100644--- a/backend/apps/production/src/analytics/analytics.controller.ts+++ b/backend/apps/production/src/analytics/analytics.controller.ts@@ -36,7 +36,6 @@ import { OptionalJwtAccessTokenGuard } from '../auth/guards'import { Auth, Public } from '../auth/decorators'import {AnalyticsService,- getHeartbeatKey,DataType,getLowestPossibleTimeBucket,} from './analytics.service'@@ -54,7 +53,6 @@ import { GetFunnelsDto } from './dto/getFunnels.dto'import { AppLoggerService } from '../logger/logger.service'import {redis,- HEARTBEAT_SID_LIFE_TIME,REDIS_USERS_COUNT_KEY,REDIS_PROJECTS_COUNT_KEY,REDIS_EVENTS_COUNT_KEY,@@ -1031,7 +1029,7 @@ export class AnalyticsController {)await this.analyticsService.checkBillingAccess(pid)- const keys = await redis.keys(`hb:*:${pid}`)+ const keys = await redis.keys(`sd:*:${pid}`)if (_isEmpty(keys)) {return []}@@ -1045,11 +1043,34 @@ export class AnalyticsController {any(os) AS os,any(cc) AS cc,toString(psid) AS psid- FROM analytics- WHERE- psid IN ({ psids: Array(String) })- AND created > ({ createdAfter: String })- AND pid = ({ pid: FixedString(12) })+ FROM+ (+ SELECT+ psid,+ dv,+ br,+ os,+ cc,+ created+ FROM analytics+ WHERE+ psid IN ({ psids: Array(String) })+ AND created > ({ createdAfter: String })+ AND pid = ({ pid: FixedString(12) })+ UNION ALL+ SELECT+ psid,+ dv,+ br,+ os,+ cc,+ created+ FROM customEV+ WHERE+ psid IN ({ psids: Array(String) })+ AND created > ({ createdAfter: String })+ AND pid = ({ pid: FixedString(12) })+ )GROUP BY psid`@@ -1259,12 +1280,6 @@ export class AnalyticsController {const [, psid] = await this.analyticsService.isUnique(pid, userAgent, ip)- await redis.set(- getHeartbeatKey(psid, pid),- 1,- 'EX',- HEARTBEAT_SID_LIFE_TIME,- )await this.analyticsService.processInteractionSD(psid, pid)}diff --git a/backend/apps/production/src/analytics/analytics.service.ts b/backend/apps/production/src/analytics/analytics.service.tsindex 2135216a8..91e7cbe07 100644--- a/backend/apps/production/src/analytics/analytics.service.ts+++ b/backend/apps/production/src/analytics/analytics.service.ts@@ -109,9 +109,6 @@ dayjs.extend(utc)dayjs.extend(dayjsTimezone)dayjs.extend(isSameOrBefore)-export const getHeartbeatKey = (psid: string, pid: string) =>- `hb:${psid}:${pid}`-const getSessionDurationKey = (psid: string, pid: string) => `sd:${psid}:${pid}`const GMT_0_TIMEZONES = [@@ -3562,7 +3559,7 @@ export class AnalyticsService {async getOnlineUserCount(pid: string): Promise<number> {// @ts-expect-error- return redis.countKeysByPattern(`hb:*:${pid}`)+ return redis.countKeysByPattern(`sd:*:${pid}`)}async groupCustomEVByTimeBucket(diff --git a/backend/apps/production/src/common/constants.ts b/backend/apps/production/src/common/constants.tsindex 31cbcead3..1acb47686 100644--- a/backend/apps/production/src/common/constants.ts+++ b/backend/apps/production/src/common/constants.ts@@ -69,9 +69,6 @@ const redisUserUsageinfoCacheTimeout = 300// 30 minues -> the amount of time analytics requests within one session are counted as non-uniqueconst UNIQUE_SESSION_LIFE_TIME = 1800-// 35 seconds-const HEARTBEAT_SID_LIFE_TIME = 35-const AFFILIATE_CUT = 0.2// how often can user request a fresh GDPR export of their data; in days.@@ -187,7 +184,6 @@ export {getRedisUserCountKey,redisProjectCountCacheTimeout,REDIS_SESSION_SALT_KEY,- HEARTBEAT_SID_LIFE_TIME,REDIS_USERS_COUNT_KEY,REDIS_PROJECTS_COUNT_KEY,REDIS_EVENTS_COUNT_KEY,diff --git a/backend/apps/selfhosted/src/analytics/analytics.controller.ts b/backend/apps/selfhosted/src/analytics/analytics.controller.tsindex 1cab1a1be..f945fce43 100644--- a/backend/apps/selfhosted/src/analytics/analytics.controller.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.controller.ts@@ -29,7 +29,6 @@ import { OptionalJwtAccessTokenGuard } from '../auth/guards'import { Auth, Public } from '../auth/decorators'import {AnalyticsService,- getHeartbeatKey,DataType,getLowestPossibleTimeBucket,} from './analytics.service'@@ -46,7 +45,7 @@ import { GetPagePropertyMetaDto } from './dto/get-page-property-meta.dto'import { GetUserFlowDto } from './dto/getUserFlow.dto'import { GetFunnelsDto } from './dto/getFunnels.dto'import { AppLoggerService } from '../logger/logger.service'-import { redis, HEARTBEAT_SID_LIFE_TIME } from '../common/constants'+import { redis } from '../common/constants'import { clickhouse } from '../common/integrations/clickhouse'import {checkRateLimit,@@ -833,7 +832,7 @@ export class AnalyticsController {headers['x-password'],)- const keys = await redis.keys(`hb:*:${pid}`)+ const keys = await redis.keys(`sd:*:${pid}`)if (_isEmpty(keys)) {return []}@@ -847,11 +846,34 @@ export class AnalyticsController {any(os) AS os,any(cc) AS cc,toString(psid) AS psid- FROM analytics- WHERE- psid IN ({ psids: Array(String) })- AND created > ({ createdAfter: String })- AND pid = ({ pid: FixedString(12) })+ FROM+ (+ SELECT+ psid,+ dv,+ br,+ os,+ cc,+ created+ FROM analytics+ WHERE+ psid IN ({ psids: Array(String) })+ AND created > ({ createdAfter: String })+ AND pid = ({ pid: FixedString(12) })+ UNION ALL+ SELECT+ psid,+ dv,+ br,+ os,+ cc,+ created+ FROM customEV+ WHERE+ psid IN ({ psids: Array(String) })+ AND created > ({ createdAfter: String })+ AND pid = ({ pid: FixedString(12) })+ )GROUP BY psid`@@ -976,12 +998,6 @@ export class AnalyticsController {const [, psid] = await this.analyticsService.isUnique(pid, userAgent, ip)- await redis.set(- getHeartbeatKey(psid, pid),- 1,- 'EX',- HEARTBEAT_SID_LIFE_TIME,- )await this.analyticsService.processInteractionSD(psid, pid)}diff --git a/backend/apps/selfhosted/src/analytics/analytics.service.ts b/backend/apps/selfhosted/src/analytics/analytics.service.tsindex 64ca4b515..9f5945f02 100644--- a/backend/apps/selfhosted/src/analytics/analytics.service.ts+++ b/backend/apps/selfhosted/src/analytics/analytics.service.ts@@ -98,9 +98,6 @@ dayjs.extend(utc)dayjs.extend(dayjsTimezone)dayjs.extend(isSameOrBefore)-export const getHeartbeatKey = (psid: string, pid: string) =>- `hb:${psid}:${pid}`-const getSessionDurationKey = (psid: string, pid: string) => `sd:${psid}:${pid}`const GMT_0_TIMEZONES = [@@ -2960,7 +2957,7 @@ export class AnalyticsService {async getOnlineUserCount(pid: string): Promise<number> {// @ts-expect-error- return redis.countKeysByPattern(`hb:*:${pid}`)+ return redis.countKeysByPattern(`sd:*:${pid}`)}async groupCustomEVByTimeBucket(diff --git a/backend/apps/selfhosted/src/common/constants.ts b/backend/apps/selfhosted/src/common/constants.tsindex 0201be6c8..e633276cd 100644--- a/backend/apps/selfhosted/src/common/constants.ts+++ b/backend/apps/selfhosted/src/common/constants.ts@@ -58,9 +58,6 @@ const redisProjectCacheTimeout = 3600// 30 minues -> the amount of time analytics requests within one session are counted as non-uniqueconst UNIQUE_SESSION_LIFE_TIME = 1800-// 35 seconds-const HEARTBEAT_SID_LIFE_TIME = 35-// Funnelsconst MIN_PAGES_IN_FUNNEL = 2const MAX_PAGES_IN_FUNNEL = 10@@ -114,7 +111,6 @@ export {UNIQUE_SESSION_LIFE_TIME,TRAFFIC_METAKEY_COLUMNS,REDIS_SESSION_SALT_KEY,- HEARTBEAT_SID_LIFE_TIME,UUIDV5_NAMESPACE,SELFHOSTED_EMAIL,SELFHOSTED_PASSWORD,