mirror of
https://github.com/umami-software/umami.git
synced 2026-02-20 04:25:39 +01:00
func(session): add ip for clickhouse
This commit is contained in:
parent
4ee98cec8d
commit
f89c08b007
2 changed files with 95 additions and 0 deletions
91
db/clickhouse/migrations/04_add_ip.sql
Normal file
91
db/clickhouse/migrations/04_add_ip.sql
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
CREATE TABLE umami.website_event_join
|
||||||
|
(
|
||||||
|
session_id UUID,
|
||||||
|
ip String,
|
||||||
|
created_at DateTime('UTC')
|
||||||
|
)
|
||||||
|
engine = MergeTree
|
||||||
|
ORDER BY (session_id, created_at)
|
||||||
|
SETTINGS index_granularity = 8192;
|
||||||
|
|
||||||
|
INSERT INTO umami.website_event_join
|
||||||
|
SELECT DISTINCT
|
||||||
|
s.session_id,
|
||||||
|
"",
|
||||||
|
s.created_at
|
||||||
|
FROM (SELECT DISTINCT session_id,
|
||||||
|
date_trunc('hour', created_at) created_at
|
||||||
|
FROM website_event) s;
|
||||||
|
|
||||||
|
-- create new table
|
||||||
|
CREATE TABLE umami.website_event_new
|
||||||
|
(
|
||||||
|
website_id UUID,
|
||||||
|
session_id UUID,
|
||||||
|
visit_id UUID,
|
||||||
|
event_id UUID,
|
||||||
|
hostname LowCardinality(String),
|
||||||
|
browser LowCardinality(String),
|
||||||
|
os LowCardinality(String),
|
||||||
|
device LowCardinality(String),
|
||||||
|
screen LowCardinality(String),
|
||||||
|
language LowCardinality(String),
|
||||||
|
country LowCardinality(String),
|
||||||
|
subdivision1 LowCardinality(String),
|
||||||
|
subdivision2 LowCardinality(String),
|
||||||
|
city String,
|
||||||
|
ip String,
|
||||||
|
url_path String,
|
||||||
|
url_query String,
|
||||||
|
referrer_path String,
|
||||||
|
referrer_query String,
|
||||||
|
referrer_domain String,
|
||||||
|
page_title String,
|
||||||
|
event_type UInt32,
|
||||||
|
event_name String,
|
||||||
|
created_at DateTime('UTC'),
|
||||||
|
job_id UUID
|
||||||
|
)
|
||||||
|
engine = MergeTree
|
||||||
|
ORDER BY (website_id, session_id, created_at)
|
||||||
|
SETTINGS index_granularity = 8192;
|
||||||
|
|
||||||
|
INSERT INTO umami.website_event_new
|
||||||
|
SELECT we.website_id,
|
||||||
|
we.session_id,
|
||||||
|
we.event_id,
|
||||||
|
we.hostname,
|
||||||
|
we.browser,
|
||||||
|
we.os,
|
||||||
|
we.device,
|
||||||
|
we.screen,
|
||||||
|
we.language,
|
||||||
|
we.country,
|
||||||
|
we.subdivision1,
|
||||||
|
we.subdivision2,
|
||||||
|
we.city,
|
||||||
|
j.ip,
|
||||||
|
we.url_path,
|
||||||
|
we.url_query,
|
||||||
|
we.referrer_path,
|
||||||
|
we.referrer_query,
|
||||||
|
we.referrer_domain,
|
||||||
|
we.page_title,
|
||||||
|
we.event_type,
|
||||||
|
we.event_name,
|
||||||
|
we.created_at,
|
||||||
|
we.job_id
|
||||||
|
FROM umami.website_event we
|
||||||
|
JOIN umami.website_event_join j
|
||||||
|
ON we.session_id = j.session_id
|
||||||
|
and date_trunc('hour', we.created_at) = j.created_at
|
||||||
|
|
||||||
|
RENAME TABLE umami.website_event TO umami.website_event_old;
|
||||||
|
RENAME TABLE umami.website_event_new TO umami.website_event;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
DROP TABLE umami.website_event_old
|
||||||
|
DROP TABLE umami.website_event_join
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
@ -86,6 +86,7 @@ CREATE TABLE umami.website_event_stats_hourly
|
||||||
country LowCardinality(String),
|
country LowCardinality(String),
|
||||||
subdivision1 LowCardinality(String),
|
subdivision1 LowCardinality(String),
|
||||||
city String,
|
city String,
|
||||||
|
ip String,
|
||||||
entry_url AggregateFunction(argMin, String, DateTime('UTC')),
|
entry_url AggregateFunction(argMin, String, DateTime('UTC')),
|
||||||
exit_url AggregateFunction(argMax, String, DateTime('UTC')),
|
exit_url AggregateFunction(argMax, String, DateTime('UTC')),
|
||||||
url_path SimpleAggregateFunction(groupArrayArray, Array(String)),
|
url_path SimpleAggregateFunction(groupArrayArray, Array(String)),
|
||||||
|
|
@ -126,6 +127,7 @@ SELECT
|
||||||
country,
|
country,
|
||||||
subdivision1,
|
subdivision1,
|
||||||
city,
|
city,
|
||||||
|
ip,
|
||||||
entry_url,
|
entry_url,
|
||||||
exit_url,
|
exit_url,
|
||||||
url_paths as url_path,
|
url_paths as url_path,
|
||||||
|
|
@ -151,6 +153,7 @@ FROM (SELECT
|
||||||
country,
|
country,
|
||||||
subdivision1,
|
subdivision1,
|
||||||
city,
|
city,
|
||||||
|
ip,
|
||||||
argMinState(url_path, created_at) entry_url,
|
argMinState(url_path, created_at) entry_url,
|
||||||
argMaxState(url_path, created_at) exit_url,
|
argMaxState(url_path, created_at) exit_url,
|
||||||
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
|
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
|
||||||
|
|
@ -176,6 +179,7 @@ GROUP BY website_id,
|
||||||
country,
|
country,
|
||||||
subdivision1,
|
subdivision1,
|
||||||
city,
|
city,
|
||||||
|
ip,
|
||||||
event_type,
|
event_type,
|
||||||
timestamp);
|
timestamp);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue