Skip to content

📈 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!

Selfhosted: Browser / OS versions

Blue Mouse9dc7e371c2bc
diff --git a/backend/apps/selfhosted/src/analytics/analytics.controller.ts b/backend/apps/selfhosted/src/analytics/analytics.controller.ts
index bd73bbfae..9fff8531f 100644
--- a/backend/apps/selfhosted/src/analytics/analytics.controller.ts
+++ b/backend/apps/selfhosted/src/analytics/analytics.controller.ts
@@ -905,7 +905,11 @@ export class AnalyticsController {
const ua = UAParser(userAgent, extensions)
const dv = ua.device.type || 'desktop'
const br = ua.browser.name
+ const brv = this.analyticsService.extractMajorMinorVersion(
+ ua.browser.version,
+ )
const os = ua.os.name
+ const osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)
const { city, region, country } = getGeoDetails(ip, eventsDTO.tz, headers)
@@ -922,7 +926,9 @@ export class AnalyticsController {
eventsDTO.pg,
dv,
br,
+ brv,
os,
+ osv,
eventsDTO.lc,
eventsDTO.ref,
eventsDTO.so,
@@ -1009,7 +1015,11 @@ export class AnalyticsController {
const ua = UAParser(userAgent, extensions)
const dv = ua.device.type || 'desktop'
const br = ua.browser.name
+ const brv = this.analyticsService.extractMajorMinorVersion(
+ ua.browser.version,
+ )
const os = ua.os.name
+ const osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)
const transformed = trafficTransformer(
psid,
@@ -1018,7 +1028,9 @@ export class AnalyticsController {
logDTO.prev,
dv,
br,
+ brv,
os,
+ osv,
logDTO.lc,
logDTO.ref,
logDTO.so,
@@ -1053,6 +1065,7 @@ export class AnalyticsController {
logDTO.pg,
dv,
br,
+ brv,
country,
region,
city,
@@ -1134,7 +1147,11 @@ export class AnalyticsController {
const ua = UAParser(userAgent, extensions)
const dv = ua.device.type || 'desktop'
const br = ua.browser.name
+ const brv = this.analyticsService.extractMajorMinorVersion(
+ ua.browser.version,
+ )
const os = ua.os.name
+ const osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)
const { city, region, country } = getGeoDetails(ip, null, headers)
@@ -1145,7 +1162,9 @@ export class AnalyticsController {
null,
dv,
br,
+ brv,
os,
+ osv,
null,
null,
null,
@@ -1422,7 +1441,11 @@ export class AnalyticsController {
const ua = UAParser(userAgent, extensions)
const dv = ua.device.type || 'desktop'
const br = ua.browser.name
+ const brv = this.analyticsService.extractMajorMinorVersion(
+ ua.browser.version,
+ )
const os = ua.os.name
+ const osv = this.analyticsService.extractMajorMinorVersion(ua.os.version)
const { name, message, lineno, colno, filename } = errorDTO
@@ -1432,7 +1455,9 @@ export class AnalyticsController {
errorDTO.pg,
dv,
br,
+ brv,
os,
+ osv,
errorDTO.lc,
country,
region,
diff --git a/backend/apps/selfhosted/src/analytics/analytics.service.ts b/backend/apps/selfhosted/src/analytics/analytics.service.ts
index 0c9ec66e0..1a1cb3754 100644
--- a/backend/apps/selfhosted/src/analytics/analytics.service.ts
+++ b/backend/apps/selfhosted/src/analytics/analytics.service.ts
@@ -248,6 +248,13 @@ const generateParamsQuery = (
columns = [...columns, 'cc']
}
+ // For browser version and OS version, include the browser or OS name
+ if (col === 'brv') {
+ columns = [...columns, 'br']
+ } else if (col === 'osv') {
+ columns = [...columns, 'os']
+ }
+
const columnsQuery = columns.join(', ')
if (type === 'performance') {
@@ -2362,6 +2369,16 @@ export class AnalyticsService {
})
}
+ extractMajorMinorVersion(version: string | null): string | null {
+ if (!version) return null
+
+ const [major, minor = '0'] = version.split('.')
+
+ if (!major) return null
+
+ return `${major}.${minor}`
+ }
+
async groupErrorsByTimeBucket(
timeBucket: TimeBucketType,
from: string,
diff --git a/backend/apps/selfhosted/src/analytics/utils/transformers.ts b/backend/apps/selfhosted/src/analytics/utils/transformers.ts
index 95787a1fa..2d213eb4a 100644
--- a/backend/apps/selfhosted/src/analytics/utils/transformers.ts
+++ b/backend/apps/selfhosted/src/analytics/utils/transformers.ts
@@ -30,7 +30,9 @@ export const trafficTransformer = (
prev: string | null,
dv: string | null,
br: string | null,
+ brv: string | null,
os: string | null,
+ osv: string | null,
lc: string | null,
ref: string | null,
so: string | null,
@@ -52,7 +54,9 @@ export const trafficTransformer = (
prev: prev || null,
dv: dv || null,
br: br || null,
+ brv: brv || null,
os: os || null,
+ osv: osv || null,
lc: lc || null,
ref: ref || null,
so: so || null,
@@ -77,7 +81,9 @@ export const customEventTransformer = (
pg: string | null,
dv: string | null,
br: string | null,
+ brv: string | null,
os: string | null,
+ osv: string | null,
lc: string | null,
ref: string | null,
so: string | null,
@@ -97,7 +103,9 @@ export const customEventTransformer = (
pg: pg || null,
dv: dv || null,
br: br || null,
+ brv: brv || null,
os: os || null,
+ osv: osv || null,
lc: lc || null,
ref: ref || null,
so: so || null,
@@ -119,7 +127,9 @@ export const errorEventTransformer = (
pg: string | null,
dv: string | null,
br: string | null,
+ brv: string | null,
os: string | null,
+ osv: string | null,
lc: string | null,
cc: string | null,
rg: string | null,
@@ -136,7 +146,9 @@ export const errorEventTransformer = (
pg: pg || null,
dv: dv || null,
br: br || null,
+ brv: brv || null,
os: os || null,
+ osv: osv || null,
lc: lc || null,
cc: cc || null,
rg: rg || null,
@@ -155,6 +167,7 @@ export const performanceTransformer = (
pg: string | null,
dv: string | null,
br: string | null,
+ brv: string | null,
cc: string | null,
rg: string | null,
ct: string | null,
@@ -172,6 +185,7 @@ export const performanceTransformer = (
pg: pg || null,
dv: dv || null,
br: br || null,
+ brv: brv || null,
cc: cc || null,
rg: rg || null,
ct: ct || null,
diff --git a/backend/apps/selfhosted/src/common/constants.ts b/backend/apps/selfhosted/src/common/constants.ts
index cfca56e9e..0201be6c8 100644
--- a/backend/apps/selfhosted/src/common/constants.ts
+++ b/backend/apps/selfhosted/src/common/constants.ts
@@ -72,7 +72,9 @@ const TRAFFIC_COLUMNS = [
'pg',
'lc',
'br',
+ 'brv',
'os',
+ 'osv',
'dv',
'ref',
'so',
@@ -82,12 +84,24 @@ const TRAFFIC_COLUMNS = [
'co',
]
-const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']
-
const TRAFFIC_METAKEY_COLUMNS = ['tag:key', 'tag:value']
-const PERFORMANCE_COLUMNS = ['cc', 'rg', 'ct', 'pg', 'dv', 'br']
-const ERROR_COLUMNS = ['pg', 'dv', 'br', 'os', 'lc', 'cc', 'rg', 'ct']
+const ERROR_COLUMNS = [
+ 'pg',
+ 'dv',
+ 'br',
+ 'brv',
+ 'os',
+ 'osv',
+ 'lc',
+ 'cc',
+ 'rg',
+ 'ct',
+]
+
+const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']
+
+const PERFORMANCE_COLUMNS = ['cc', 'rg', 'ct', 'pg', 'dv', 'br', 'brv']
const NUMBER_JWT_REFRESH_TOKEN_LIFETIME = Number(JWT_REFRESH_TOKEN_LIFETIME)
const NUMBER_JWT_ACCESS_TOKEN_LIFETIME = Number(JWT_ACCESS_TOKEN_LIFETIME)