📈 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
const { queriesRunner, dbName } = require('./setup')
const queries = [
// Analytics -> LowCardinality
`DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
(
sid Nullable(String),
pid FixedString(12),
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),
cc Nullable(FixedString(2)),
sdur Nullable(UInt32),
unique UInt8,
created DateTime
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.analytics_temp (sid, pid, pg, dv, br, os, lc, ref, so, me, ca, cc, sdur, unique, created)
SELECT sid, pid, pg, dv, br, os, lc, ref, so, me, ca, cc, sdur, unique, created FROM ${dbName}.analytics`,
`DROP TABLE ${dbName}.analytics`,
`RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
// Custom events -> LowCardinality
`DROP TABLE IF EXISTS ${dbName}.customEV_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.customEV_temp
(
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),
cc Nullable(FixedString(2)),
created DateTime
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.customEV_temp (pid, ev, pg, dv, br, os, lc, ref, so, me, ca, cc, created)
SELECT pid, ev, pg, dv, br, os, lc, ref, so, me, ca, cc, created FROM ${dbName}.customEV`,
`DROP TABLE ${dbName}.customEV`,
`RENAME TABLE ${dbName}.customEV_temp TO ${dbName}.customEV`,
// Performance -> LowCardinality
`DROP TABLE IF EXISTS ${dbName}.performance_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.performance_temp
(
pid FixedString(12),
pg Nullable(String),
dv LowCardinality(Nullable(String)),
br LowCardinality(Nullable(String)),
cc Nullable(FixedString(2)),
dns Nullable(UInt32),
tls Nullable(UInt32),
conn Nullable(UInt32),
response Nullable(UInt32),
render Nullable(UInt32),
domLoad Nullable(UInt32),
pageLoad Nullable(UInt32),
ttfb Nullable(UInt32),
created DateTime
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.performance_temp (pid, pg, dv, br, cc, dns, tls, conn, response, render, domLoad, pageLoad, ttfb, created)
SELECT pid, pg, dv, br, cc, dns, tls, conn, response, render, domLoad, pageLoad, ttfb, created FROM ${dbName}.performance`,
`DROP TABLE ${dbName}.performance`,
`RENAME TABLE ${dbName}.performance_temp TO ${dbName}.performance`,
]
queriesRunner(queries)