|
| 1 | +-- ============================================================================ |
| 2 | +-- Events Table |
| 3 | +-- ============================================================================ |
| 4 | +-- Main analytics events table storing all user interactions and page views |
| 5 | +-- ============================================================================ |
| 6 | + |
| 7 | +CREATE TABLE IF NOT EXISTS analytics.events ( |
| 8 | + id UUID, |
| 9 | + client_id String, |
| 10 | + event_name String, |
| 11 | + anonymous_id String, |
| 12 | + time DateTime64(3, 'UTC'), |
| 13 | + session_id String, |
| 14 | + |
| 15 | + -- Event metadata |
| 16 | + event_type LowCardinality(String) DEFAULT 'track', |
| 17 | + event_id Nullable(String), |
| 18 | + session_start_time Nullable(DateTime64(3, 'UTC')), |
| 19 | + timestamp DateTime64(3, 'UTC') DEFAULT time, |
| 20 | + |
| 21 | + -- Page information |
| 22 | + referrer Nullable(String), |
| 23 | + url String, |
| 24 | + path String, |
| 25 | + title Nullable(String), |
| 26 | + |
| 27 | + -- User information |
| 28 | + ip String, |
| 29 | + user_agent String, |
| 30 | + browser_name Nullable(String), |
| 31 | + browser_version Nullable(String), |
| 32 | + os_name Nullable(String), |
| 33 | + os_version Nullable(String), |
| 34 | + device_type Nullable(String), |
| 35 | + device_brand Nullable(String), |
| 36 | + device_model Nullable(String), |
| 37 | + |
| 38 | + -- Geographic information |
| 39 | + country Nullable(String), |
| 40 | + region Nullable(String), |
| 41 | + city Nullable(String), |
| 42 | + |
| 43 | + -- Device specifications |
| 44 | + screen_resolution Nullable(String), |
| 45 | + viewport_size Nullable(String), |
| 46 | + language Nullable(String), |
| 47 | + timezone Nullable(String), |
| 48 | + |
| 49 | + -- Network information |
| 50 | + connection_type Nullable(String), |
| 51 | + rtt Nullable(Int16), |
| 52 | + downlink Nullable(Float32), |
| 53 | + |
| 54 | + -- User behavior metrics |
| 55 | + time_on_page Nullable(Float32), |
| 56 | + scroll_depth Nullable(Float32), |
| 57 | + interaction_count Nullable(Int16), |
| 58 | + page_count UInt8 DEFAULT 1, |
| 59 | + |
| 60 | + -- UTM parameters |
| 61 | + utm_source Nullable(String), |
| 62 | + utm_medium Nullable(String), |
| 63 | + utm_campaign Nullable(String), |
| 64 | + utm_term Nullable(String), |
| 65 | + utm_content Nullable(String), |
| 66 | + |
| 67 | + -- Performance metrics |
| 68 | + load_time Nullable(Int32), |
| 69 | + dom_ready_time Nullable(Int32), |
| 70 | + dom_interactive Nullable(Int32), |
| 71 | + ttfb Nullable(Int32), |
| 72 | + connection_time Nullable(Int32), |
| 73 | + request_time Nullable(Int32), |
| 74 | + render_time Nullable(Int32), |
| 75 | + redirect_time Nullable(Int32), |
| 76 | + domain_lookup_time Nullable(Int32), |
| 77 | + |
| 78 | + -- Additional data |
| 79 | + properties String, |
| 80 | + created_at DateTime64(3, 'UTC') |
| 81 | +) ENGINE = MergeTree() |
| 82 | +PARTITION BY toYYYYMM(time) |
| 83 | +ORDER BY (client_id, time, id) |
| 84 | +SETTINGS index_granularity = 8192; |
0 commit comments