📈 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 table
`DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
(
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),
cc Nullable(FixedString(2)),
sdur Nullable(UInt32),
unique UInt8,
created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.analytics_temp (*) SELECT * FROM ${dbName}.analytics`,
`DROP TABLE ${dbName}.analytics`,
`RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
// Custom events table
`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('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.customEV_temp (*) SELECT * FROM ${dbName}.customEV`,
`DROP TABLE ${dbName}.customEV`,
`RENAME TABLE ${dbName}.customEV_temp TO ${dbName}.customEV`,
// Performance table
`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('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.performance_temp (*) SELECT * FROM ${dbName}.performance`,
`DROP TABLE ${dbName}.performance`,
`RENAME TABLE ${dbName}.performance_temp TO ${dbName}.performance`,
// Captcha table
`DROP TABLE IF EXISTS ${dbName}.captcha_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.captcha_temp
(
pid FixedString(12),
dv LowCardinality(Nullable(String)),
br LowCardinality(Nullable(String)),
os Nullable(String),
cc Nullable(FixedString(2)),
manuallyPassed UInt8,
created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
`INSERT INTO ${dbName}.captcha_temp (*) SELECT * FROM ${dbName}.captcha`,
`DROP TABLE ${dbName}.captcha`,
`RENAME TABLE ${dbName}.captcha_temp TO ${dbName}.captcha`,
]
queriesRunner(queries)