|
1 | | --- Create Performance |
2 | | -CREATE TABLE umami.website_performance |
3 | | -( |
4 | | - website_id UUID, |
5 | | - session_id UUID, |
6 | | - visit_id UUID, |
7 | | - url_path String, |
8 | | - lcp Nullable(Decimal(10, 1)), |
9 | | - inp Nullable(Decimal(10, 1)), |
10 | | - cls Nullable(Decimal(10, 4)), |
11 | | - fcp Nullable(Decimal(10, 1)), |
12 | | - ttfb Nullable(Decimal(10, 1)), |
13 | | - created_at DateTime('UTC') |
14 | | -) |
15 | | -ENGINE = MergeTree |
16 | | - PARTITION BY toYYYYMM(created_at) |
17 | | - ORDER BY (website_id, toStartOfHour(created_at), session_id) |
18 | | - SETTINGS index_granularity = 8192; |
| 1 | +-- Add performance columns to website_event |
| 2 | +ALTER TABLE umami.website_event ADD COLUMN lcp Nullable(Decimal(10, 1)) AFTER twclid; |
| 3 | +ALTER TABLE umami.website_event ADD COLUMN inp Nullable(Decimal(10, 1)) AFTER lcp; |
| 4 | +ALTER TABLE umami.website_event ADD COLUMN cls Nullable(Decimal(10, 4)) AFTER inp; |
| 5 | +ALTER TABLE umami.website_event ADD COLUMN fcp Nullable(Decimal(10, 1)) AFTER cls; |
| 6 | +ALTER TABLE umami.website_event ADD COLUMN ttfb Nullable(Decimal(10, 1)) AFTER fcp; |
19 | 7 |
|
20 | | --- Performance hourly aggregation |
21 | | -CREATE TABLE umami.website_performance_hourly |
22 | | -( |
23 | | - website_id UUID, |
24 | | - url_path String, |
25 | | - lcp_p50 AggregateFunction(quantile(0.5), Nullable(Decimal(10, 1))), |
26 | | - lcp_p75 AggregateFunction(quantile(0.75), Nullable(Decimal(10, 1))), |
27 | | - lcp_p95 AggregateFunction(quantile(0.95), Nullable(Decimal(10, 1))), |
28 | | - inp_p50 AggregateFunction(quantile(0.5), Nullable(Decimal(10, 1))), |
29 | | - inp_p75 AggregateFunction(quantile(0.75), Nullable(Decimal(10, 1))), |
30 | | - inp_p95 AggregateFunction(quantile(0.95), Nullable(Decimal(10, 1))), |
31 | | - cls_p50 AggregateFunction(quantile(0.5), Nullable(Decimal(10, 4))), |
32 | | - cls_p75 AggregateFunction(quantile(0.75), Nullable(Decimal(10, 4))), |
33 | | - cls_p95 AggregateFunction(quantile(0.95), Nullable(Decimal(10, 4))), |
34 | | - fcp_p50 AggregateFunction(quantile(0.5), Nullable(Decimal(10, 1))), |
35 | | - fcp_p75 AggregateFunction(quantile(0.75), Nullable(Decimal(10, 1))), |
36 | | - fcp_p95 AggregateFunction(quantile(0.95), Nullable(Decimal(10, 1))), |
37 | | - ttfb_p50 AggregateFunction(quantile(0.5), Nullable(Decimal(10, 1))), |
38 | | - ttfb_p75 AggregateFunction(quantile(0.75), Nullable(Decimal(10, 1))), |
39 | | - ttfb_p95 AggregateFunction(quantile(0.95), Nullable(Decimal(10, 1))), |
40 | | - sample_count SimpleAggregateFunction(sum, UInt64), |
41 | | - created_at DateTime('UTC') |
42 | | -) |
43 | | -ENGINE = AggregatingMergeTree |
44 | | - PARTITION BY toYYYYMM(created_at) |
45 | | - ORDER BY (website_id, toStartOfHour(created_at), url_path) |
46 | | - SETTINGS index_granularity = 8192; |
| 8 | +-- Update materialized view to exclude performance events from view counts |
| 9 | +DROP TABLE umami.website_event_stats_hourly_mv; |
47 | 10 |
|
48 | | -CREATE MATERIALIZED VIEW umami.website_performance_hourly_mv |
49 | | -TO umami.website_performance_hourly |
| 11 | +CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv |
| 12 | +TO umami.website_event_stats_hourly |
50 | 13 | AS |
51 | 14 | SELECT |
52 | 15 | website_id, |
53 | | - url_path, |
54 | | - quantileState(0.5)(lcp) as lcp_p50, |
55 | | - quantileState(0.75)(lcp) as lcp_p75, |
56 | | - quantileState(0.95)(lcp) as lcp_p95, |
57 | | - quantileState(0.5)(inp) as inp_p50, |
58 | | - quantileState(0.75)(inp) as inp_p75, |
59 | | - quantileState(0.95)(inp) as inp_p95, |
60 | | - quantileState(0.5)(cls) as cls_p50, |
61 | | - quantileState(0.75)(cls) as cls_p75, |
62 | | - quantileState(0.95)(cls) as cls_p95, |
63 | | - quantileState(0.5)(fcp) as fcp_p50, |
64 | | - quantileState(0.75)(fcp) as fcp_p75, |
65 | | - quantileState(0.95)(fcp) as fcp_p95, |
66 | | - quantileState(0.5)(ttfb) as ttfb_p50, |
67 | | - quantileState(0.75)(ttfb) as ttfb_p75, |
68 | | - quantileState(0.95)(ttfb) as ttfb_p95, |
69 | | - count() as sample_count, |
70 | | - toStartOfHour(created_at) as created_at |
71 | | -FROM umami.website_performance |
72 | | -GROUP BY website_id, url_path, created_at; |
| 16 | + session_id, |
| 17 | + visit_id, |
| 18 | + hostnames as hostname, |
| 19 | + browser, |
| 20 | + os, |
| 21 | + device, |
| 22 | + screen, |
| 23 | + language, |
| 24 | + country, |
| 25 | + region, |
| 26 | + city, |
| 27 | + entry_url, |
| 28 | + exit_url, |
| 29 | + url_paths as url_path, |
| 30 | + url_query, |
| 31 | + utm_source, |
| 32 | + utm_medium, |
| 33 | + utm_campaign, |
| 34 | + utm_content, |
| 35 | + utm_term, |
| 36 | + referrer_domain, |
| 37 | + page_title, |
| 38 | + gclid, |
| 39 | + fbclid, |
| 40 | + msclkid, |
| 41 | + ttclid, |
| 42 | + li_fat_id, |
| 43 | + twclid, |
| 44 | + event_type, |
| 45 | + event_name, |
| 46 | + views, |
| 47 | + min_time, |
| 48 | + max_time, |
| 49 | + tag, |
| 50 | + distinct_id, |
| 51 | + timestamp as created_at |
| 52 | +FROM (SELECT |
| 53 | + website_id, |
| 54 | + session_id, |
| 55 | + visit_id, |
| 56 | + arrayFilter(x -> x != '', groupArray(hostname)) hostnames, |
| 57 | + browser, |
| 58 | + os, |
| 59 | + device, |
| 60 | + screen, |
| 61 | + language, |
| 62 | + country, |
| 63 | + region, |
| 64 | + city, |
| 65 | + argMinState(url_path, created_at) entry_url, |
| 66 | + argMaxState(url_path, created_at) exit_url, |
| 67 | + arrayFilter(x -> x != '', groupArray(url_path)) as url_paths, |
| 68 | + arrayFilter(x -> x != '', groupArray(url_query)) url_query, |
| 69 | + arrayFilter(x -> x != '', groupArray(utm_source)) utm_source, |
| 70 | + arrayFilter(x -> x != '', groupArray(utm_medium)) utm_medium, |
| 71 | + arrayFilter(x -> x != '', groupArray(utm_campaign)) utm_campaign, |
| 72 | + arrayFilter(x -> x != '', groupArray(utm_content)) utm_content, |
| 73 | + arrayFilter(x -> x != '', groupArray(utm_term)) utm_term, |
| 74 | + arrayFilter(x -> x != '' and x != hostname, groupArray(referrer_domain)) referrer_domain, |
| 75 | + arrayFilter(x -> x != '', groupArray(page_title)) page_title, |
| 76 | + arrayFilter(x -> x != '', groupArray(gclid)) gclid, |
| 77 | + arrayFilter(x -> x != '', groupArray(fbclid)) fbclid, |
| 78 | + arrayFilter(x -> x != '', groupArray(msclkid)) msclkid, |
| 79 | + arrayFilter(x -> x != '', groupArray(ttclid)) ttclid, |
| 80 | + arrayFilter(x -> x != '', groupArray(li_fat_id)) li_fat_id, |
| 81 | + arrayFilter(x -> x != '', groupArray(twclid)) twclid, |
| 82 | + event_type, |
| 83 | + if(event_type = 2, groupArray(event_name), []) event_name, |
| 84 | + sumIf(1, event_type NOT IN (2, 5)) views, |
| 85 | + min(created_at) min_time, |
| 86 | + max(created_at) max_time, |
| 87 | + arrayFilter(x -> x != '', groupArray(tag)) tag, |
| 88 | + distinct_id, |
| 89 | + toStartOfHour(created_at) timestamp |
| 90 | +FROM umami.website_event |
| 91 | +GROUP BY website_id, |
| 92 | + session_id, |
| 93 | + visit_id, |
| 94 | + hostname, |
| 95 | + browser, |
| 96 | + os, |
| 97 | + device, |
| 98 | + screen, |
| 99 | + language, |
| 100 | + country, |
| 101 | + region, |
| 102 | + city, |
| 103 | + event_type, |
| 104 | + distinct_id, |
| 105 | + timestamp); |
0 commit comments