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!

utm_term & utm_content support

Blue Mouse813e5ece2db5
diff --git a/apps/production/src/analytics/analytics.controller.ts b/apps/production/src/analytics/analytics.controller.ts
index 4b1fe4a1a..77cd9cbcc 100644
--- a/apps/production/src/analytics/analytics.controller.ts
+++ b/apps/production/src/analytics/analytics.controller.ts
@@ -1261,6 +1261,8 @@ export class AnalyticsController {
eventsDTO.so,
eventsDTO.me,
eventsDTO.ca,
+ eventsDTO.te,
+ eventsDTO.co,
country,
region,
city,
@@ -1360,6 +1362,8 @@ export class AnalyticsController {
logDTO.so,
logDTO.me,
logDTO.ca,
+ logDTO.te,
+ logDTO.co,
country,
region,
city,
@@ -1482,6 +1486,8 @@ export class AnalyticsController {
null,
null,
null,
+ null,
+ null,
country,
region,
city,
diff --git a/apps/production/src/analytics/dto/events.dto.ts b/apps/production/src/analytics/dto/events.dto.ts
index 2b1134b2d..5599988a0 100644
--- a/apps/production/src/analytics/dto/events.dto.ts
+++ b/apps/production/src/analytics/dto/events.dto.ts
@@ -113,6 +113,18 @@ export class EventsDTO {
})
ca?: string
+ @ApiProperty({
+ example: 'running+shoes',
+ description: 'utm_term URL parameter',
+ })
+ te?: string
+
+ @ApiProperty({
+ example: 'logolink',
+ description: 'utm_content URL parameter',
+ })
+ co?: string
+
@ApiProperty({
example: {
affiliate: 'Yes',
diff --git a/apps/production/src/analytics/dto/pageviews.dto.ts b/apps/production/src/analytics/dto/pageviews.dto.ts
index e398a6b80..c350819cd 100644
--- a/apps/production/src/analytics/dto/pageviews.dto.ts
+++ b/apps/production/src/analytics/dto/pageviews.dto.ts
@@ -67,6 +67,18 @@ export class PageviewsDTO {
})
ca?: string
+ @ApiProperty({
+ example: 'running+shoes',
+ description: 'utm_term URL parameter',
+ })
+ te?: string
+
+ @ApiProperty({
+ example: 'logolink',
+ description: 'utm_content URL parameter',
+ })
+ co?: string
+
@ApiProperty({
example: false,
description: 'If true, only unique events will be saved',
diff --git a/apps/production/src/analytics/utils/transformers.ts b/apps/production/src/analytics/utils/transformers.ts
index 1ab11b888..f88e2d6cd 100644
--- a/apps/production/src/analytics/utils/transformers.ts
+++ b/apps/production/src/analytics/utils/transformers.ts
@@ -37,6 +37,8 @@ export const trafficTransformer = (
so: string | null,
me: string | null,
ca: string | null,
+ te: string | null,
+ co: string | null,
cc: string | null,
rg: string | null,
ct: string | null,
@@ -58,6 +60,8 @@ export const trafficTransformer = (
so: so || null,
me: me || null,
ca: ca || null,
+ te: te || null,
+ co: co || null,
cc: cc || null,
rg: rg || null,
ct: ct || null,
@@ -81,6 +85,8 @@ export const customEventTransformer = (
so: string | null,
me: string | null,
ca: string | null,
+ te: string | null,
+ co: string | null,
cc: string | null,
rg: string | null,
ct: string | null,
@@ -99,6 +105,8 @@ export const customEventTransformer = (
so: so || null,
me: me || null,
ca: ca || null,
+ te: te || null,
+ co: co || null,
cc: cc || null,
rg: rg || null,
ct: ct || null,
diff --git a/apps/production/src/common/constants.ts b/apps/production/src/common/constants.ts
index fdeb461ad..12a6e15c8 100644
--- a/apps/production/src/common/constants.ts
+++ b/apps/production/src/common/constants.ts
@@ -110,6 +110,8 @@ const TRAFFIC_COLUMNS = [
'so',
'me',
'ca',
+ 'te',
+ 'co',
]
const UPTIME_COLUMNS = ['region', 'statusCode']
diff --git a/apps/selfhosted/src/analytics/analytics.controller.ts b/apps/selfhosted/src/analytics/analytics.controller.ts
index 417aea6c0..760028bc5 100644
--- a/apps/selfhosted/src/analytics/analytics.controller.ts
+++ b/apps/selfhosted/src/analytics/analytics.controller.ts
@@ -978,6 +978,8 @@ export class AnalyticsController {
eventsDTO.so,
eventsDTO.me,
eventsDTO.ca,
+ eventsDTO.te,
+ eventsDTO.co,
country,
region,
city,
@@ -1078,6 +1080,8 @@ export class AnalyticsController {
logDTO.so,
logDTO.me,
logDTO.ca,
+ logDTO.te,
+ logDTO.co,
country,
region,
city,
@@ -1200,6 +1204,8 @@ export class AnalyticsController {
null,
null,
null,
+ null,
+ null,
country,
region,
city,
diff --git a/apps/selfhosted/src/analytics/dto/events.dto.ts b/apps/selfhosted/src/analytics/dto/events.dto.ts
index 2b1134b2d..5599988a0 100644
--- a/apps/selfhosted/src/analytics/dto/events.dto.ts
+++ b/apps/selfhosted/src/analytics/dto/events.dto.ts
@@ -113,6 +113,18 @@ export class EventsDTO {
})
ca?: string
+ @ApiProperty({
+ example: 'running+shoes',
+ description: 'utm_term URL parameter',
+ })
+ te?: string
+
+ @ApiProperty({
+ example: 'logolink',
+ description: 'utm_content URL parameter',
+ })
+ co?: string
+
@ApiProperty({
example: {
affiliate: 'Yes',
diff --git a/apps/selfhosted/src/analytics/dto/pageviews.dto.ts b/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
index e398a6b80..c350819cd 100644
--- a/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
+++ b/apps/selfhosted/src/analytics/dto/pageviews.dto.ts
@@ -67,6 +67,18 @@ export class PageviewsDTO {
})
ca?: string
+ @ApiProperty({
+ example: 'running+shoes',
+ description: 'utm_term URL parameter',
+ })
+ te?: string
+
+ @ApiProperty({
+ example: 'logolink',
+ description: 'utm_content URL parameter',
+ })
+ co?: string
+
@ApiProperty({
example: false,
description: 'If true, only unique events will be saved',
diff --git a/apps/selfhosted/src/analytics/utils/transformers.ts b/apps/selfhosted/src/analytics/utils/transformers.ts
index 1ab11b888..f88e2d6cd 100644
--- a/apps/selfhosted/src/analytics/utils/transformers.ts
+++ b/apps/selfhosted/src/analytics/utils/transformers.ts
@@ -37,6 +37,8 @@ export const trafficTransformer = (
so: string | null,
me: string | null,
ca: string | null,
+ te: string | null,
+ co: string | null,
cc: string | null,
rg: string | null,
ct: string | null,
@@ -58,6 +60,8 @@ export const trafficTransformer = (
so: so || null,
me: me || null,
ca: ca || null,
+ te: te || null,
+ co: co || null,
cc: cc || null,
rg: rg || null,
ct: ct || null,
@@ -81,6 +85,8 @@ export const customEventTransformer = (
so: string | null,
me: string | null,
ca: string | null,
+ te: string | null,
+ co: string | null,
cc: string | null,
rg: string | null,
ct: string | null,
@@ -99,6 +105,8 @@ export const customEventTransformer = (
so: so || null,
me: me || null,
ca: ca || null,
+ te: te || null,
+ co: co || null,
cc: cc || null,
rg: rg || null,
ct: ct || null,
diff --git a/apps/selfhosted/src/common/constants.ts b/apps/selfhosted/src/common/constants.ts
index 185678276..d2e7ecde2 100644
--- a/apps/selfhosted/src/common/constants.ts
+++ b/apps/selfhosted/src/common/constants.ts
@@ -78,6 +78,8 @@ const TRAFFIC_COLUMNS = [
'so',
'me',
'ca',
+ 'te',
+ 'co',
]
const ALL_COLUMNS = [...TRAFFIC_COLUMNS, 'ev']
diff --git a/migrations/clickhouse/2024_09_13.js b/migrations/clickhouse/2024_08_13.js
similarity index 100%
rename from migrations/clickhouse/2024_09_13.js
rename to migrations/clickhouse/2024_08_13.js
diff --git a/migrations/clickhouse/2024_09_10.js b/migrations/clickhouse/2024_09_10.js
new file mode 100644
index 000000000..37b36aee2
--- /dev/null
+++ b/migrations/clickhouse/2024_09_10.js
@@ -0,0 +1,84 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ // Added 'te' / 'co' columns
+ `DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
+ (
+ psid Nullable(UInt64),
+ sid Nullable(String),
+ pid FixedString(12),
+ pg Nullable(String),
+ prev Nullable(String),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os LowCardinality(Nullable(String)),
+ lc LowCardinality(Nullable(String)),
+ ref Nullable(String),
+ so Nullable(String),
+ me Nullable(String),
+ ca Nullable(String),
+ te Nullable(String),
+ co Nullable(String),
+ cc Nullable(FixedString(2)),
+ rg LowCardinality(Nullable(String)),
+ ct Nullable(String),
+ meta Nested
+ (
+ key String,
+ value String
+ ),
+ sdur Nullable(UInt32),
+ unique UInt8,
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.analytics_temp (psid, sid, pid, pg, prev, dv, br, os, lc, ref, so, me, ca, te, co, cc, rg, ct, meta.key, meta.value, sdur, unique, created)
+ SELECT psid, sid, pid, pg, prev, dv, br, os, lc, ref, so, me, ca, NULL, NULL, cc, rg, ct, meta.key, meta.value, sdur, unique, created FROM ${dbName}.analytics`,
+
+ `DROP TABLE ${dbName}.analytics`,
+ `RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
+
+ // Added 'te' / 'co' columns to custom ev
+ `DROP TABLE IF EXISTS ${dbName}.customEV_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.customEV_temp
+ (
+ psid Nullable(UInt64),
+ pid FixedString(12),
+ ev String,
+ pg Nullable(String),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os LowCardinality(Nullable(String)),
+ lc LowCardinality(Nullable(String)),
+ ref Nullable(String),
+ so Nullable(String),
+ me Nullable(String),
+ ca Nullable(String),
+ te Nullable(String),
+ co Nullable(String),
+ cc Nullable(FixedString(2)),
+ rg LowCardinality(Nullable(String)),
+ ct Nullable(String),
+ meta Nested
+ (
+ key String,
+ value String
+ ),
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.customEV_temp (psid, pid, ev, pg, dv, br, os, lc, ref, so, me, ca, te, co, cc, rg, ct, meta.key, meta.value, created)
+ SELECT psid, pid, ev, pg, dv, br, os, lc, ref, so, me, ca, NULL, NULL, cc, rg, ct, meta.key, meta.value, created FROM ${dbName}.customEV`,
+
+ `DROP TABLE ${dbName}.customEV`,
+ `RENAME TABLE ${dbName}.customEV_temp TO ${dbName}.customEV`,
+]
+
+queriesRunner(queries)
diff --git a/migrations/clickhouse/initialise_database.js b/migrations/clickhouse/initialise_database.js
index 62544cba5..172fc9b33 100644
--- a/migrations/clickhouse/initialise_database.js
+++ b/migrations/clickhouse/initialise_database.js
@@ -20,6 +20,8 @@ const CLICKHOUSE_INIT_QUERIES = [
so Nullable(String),
me Nullable(String),
ca Nullable(String),
+ te Nullable(String),
+ co Nullable(String),
cc Nullable(FixedString(2)),
rg LowCardinality(Nullable(String)),
ct Nullable(String),
@@ -51,6 +53,8 @@ const CLICKHOUSE_INIT_QUERIES = [
so Nullable(String),
me Nullable(String),
ca Nullable(String),
+ te Nullable(String),
+ co Nullable(String),
cc Nullable(FixedString(2)),
rg LowCardinality(Nullable(String)),
ct Nullable(String),