|
1 | | -import type { SimpleQueryConfig } from "../types"; |
2 | 1 | import { Analytics } from "../../types/tables"; |
| 2 | +import type { SimpleQueryConfig } from "../types"; |
3 | 3 |
|
4 | | -export const PerformanceBuilders: Record<string, SimpleQueryConfig<typeof Analytics.events>> = { |
| 4 | +export const PerformanceBuilders: Record<string, SimpleQueryConfig> = { |
5 | 5 | performance_metrics: { |
6 | | - table: Analytics.events, |
| 6 | + table: Analytics.web_vitals, |
7 | 7 | fields: [ |
8 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
9 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
10 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
11 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
12 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
13 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
14 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 8 | + 'AVG(fcp) as avg_fcp', |
| 9 | + 'AVG(lcp) as avg_lcp', |
| 10 | + 'AVG(cls) as avg_cls', |
| 11 | + 'AVG(fid) as avg_fid', |
| 12 | + 'AVG(inp) as avg_inp', |
15 | 13 | 'COUNT(*) as total_events' |
16 | 14 | ], |
17 | | - where: ['event_name = \'screen_view\''], |
18 | | - timeField: 'time', |
19 | | - allowedFilters: ['path', 'device_type', 'browser_name', 'country'], |
| 15 | + where: [], |
| 16 | + timeField: 'timestamp', |
| 17 | + allowedFilters: ['path', 'device_type', 'browser_name', 'country', 'region', 'os_name'], |
20 | 18 | customizable: true |
21 | 19 | }, |
22 | 20 |
|
23 | 21 | slow_pages: { |
24 | | - table: Analytics.events, |
| 22 | + table: Analytics.web_vitals, |
25 | 23 | fields: [ |
26 | | - 'path(path) as name', |
| 24 | + 'path as name', |
27 | 25 | 'COUNT(DISTINCT anonymous_id) as visitors', |
28 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
29 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
30 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
31 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
32 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
33 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
34 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 26 | + 'AVG(fcp) as avg_fcp', |
| 27 | + 'AVG(lcp) as avg_lcp', |
| 28 | + 'AVG(cls) as avg_cls', |
| 29 | + 'AVG(fid) as avg_fid', |
| 30 | + 'AVG(inp) as avg_inp', |
35 | 31 | 'COUNT(*) as pageviews' |
36 | 32 | ], |
37 | | - where: ['event_name = \'screen_view\'', 'path != \'\'', 'load_time > 0'], |
38 | | - groupBy: ['path(path)'], |
39 | | - orderBy: 'avg_load_time DESC', |
| 33 | + where: ["path != ''"], |
| 34 | + groupBy: ['path'], |
| 35 | + orderBy: 'avg_lcp DESC', |
40 | 36 | limit: 100, |
41 | | - timeField: 'time', |
| 37 | + timeField: 'timestamp', |
42 | 38 | allowedFilters: ['path', 'device_type', 'browser_name'], |
43 | 39 | customizable: true |
44 | 40 | }, |
45 | 41 |
|
46 | 42 | performance_by_device: { |
47 | | - table: Analytics.events, |
| 43 | + table: Analytics.web_vitals, |
48 | 44 | fields: [ |
49 | 45 | 'device_type as name', |
50 | 46 | 'COUNT(DISTINCT anonymous_id) as visitors', |
51 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
52 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
53 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
54 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
55 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
56 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
57 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 47 | + 'AVG(fcp) as avg_fcp', |
| 48 | + 'AVG(lcp) as avg_lcp', |
| 49 | + 'AVG(cls) as avg_cls', |
| 50 | + 'AVG(fid) as avg_fid', |
| 51 | + 'AVG(inp) as avg_inp', |
58 | 52 | 'COUNT(*) as pageviews' |
59 | 53 | ], |
60 | | - where: ['event_name = \'screen_view\'', 'device_type != \'\'', 'load_time > 0'], |
| 54 | + where: ["device_type != ''"], |
61 | 55 | groupBy: ['device_type'], |
62 | | - orderBy: 'avg_load_time DESC', |
| 56 | + orderBy: 'avg_lcp DESC', |
63 | 57 | limit: 100, |
64 | | - timeField: 'time', |
| 58 | + timeField: 'timestamp', |
65 | 59 | allowedFilters: ['path', 'device_type', 'browser_name'], |
66 | 60 | customizable: true |
67 | 61 | }, |
68 | 62 |
|
69 | 63 | performance_by_browser: { |
70 | | - table: Analytics.events, |
| 64 | + table: Analytics.web_vitals, |
71 | 65 | fields: [ |
72 | | - 'CONCAT(browser_name, \' \', browser_version) as name', |
| 66 | + "CONCAT(browser_name, ' ', browser_version) as name", |
73 | 67 | 'COUNT(DISTINCT anonymous_id) as visitors', |
74 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
75 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
76 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
77 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
78 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
79 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
80 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 68 | + 'AVG(fcp) as avg_fcp', |
| 69 | + 'AVG(lcp) as avg_lcp', |
| 70 | + 'AVG(cls) as avg_cls', |
| 71 | + 'AVG(fid) as avg_fid', |
| 72 | + 'AVG(inp) as avg_inp', |
81 | 73 | 'COUNT(*) as pageviews' |
82 | 74 | ], |
83 | 75 | where: [ |
84 | | - 'event_name = \'screen_view\'', |
85 | | - 'browser_name != \'\'', |
86 | | - 'browser_version != \'\'', |
87 | | - 'browser_version IS NOT NULL', |
88 | | - 'load_time > 0' |
| 76 | + "browser_name != ''", |
| 77 | + "browser_version != ''", |
| 78 | + 'browser_version IS NOT NULL' |
89 | 79 | ], |
90 | 80 | groupBy: ['browser_name', 'browser_version'], |
91 | | - orderBy: 'avg_load_time DESC', |
| 81 | + orderBy: 'avg_lcp DESC', |
92 | 82 | limit: 100, |
93 | | - timeField: 'time', |
| 83 | + timeField: 'timestamp', |
94 | 84 | allowedFilters: ['path', 'device_type', 'browser_name'], |
95 | 85 | customizable: true |
96 | 86 | }, |
97 | 87 |
|
98 | 88 | performance_by_country: { |
99 | | - table: Analytics.events, |
| 89 | + table: Analytics.web_vitals, |
100 | 90 | fields: [ |
101 | 91 | 'country as name', |
102 | 92 | 'COUNT(DISTINCT anonymous_id) as visitors', |
103 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
104 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
105 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
106 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
107 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
108 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
109 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 93 | + 'AVG(fcp) as avg_fcp', |
| 94 | + 'AVG(lcp) as avg_lcp', |
| 95 | + 'AVG(cls) as avg_cls', |
| 96 | + 'AVG(fid) as avg_fid', |
| 97 | + 'AVG(inp) as avg_inp', |
110 | 98 | 'COUNT(*) as pageviews' |
111 | 99 | ], |
112 | | - where: ['event_name = \'screen_view\'', 'country != \'\'', 'load_time > 0'], |
| 100 | + where: ["country != ''"], |
113 | 101 | groupBy: ['country'], |
114 | | - orderBy: 'avg_load_time DESC', |
| 102 | + orderBy: 'avg_lcp DESC', |
115 | 103 | limit: 100, |
116 | | - timeField: 'time', |
| 104 | + timeField: 'timestamp', |
117 | 105 | allowedFilters: ['path', 'device_type', 'browser_name'], |
118 | | - customizable: true, |
119 | | - plugins: { normalizeGeo: true, deduplicateGeo: true } |
| 106 | + customizable: true |
120 | 107 | }, |
121 | 108 |
|
122 | 109 | performance_by_os: { |
123 | | - table: Analytics.events, |
| 110 | + table: Analytics.web_vitals, |
124 | 111 | fields: [ |
125 | 112 | 'os_name as name', |
126 | 113 | 'COUNT(DISTINCT anonymous_id) as visitors', |
127 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
128 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
129 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
130 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
131 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
132 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
133 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 114 | + 'AVG(fcp) as avg_fcp', |
| 115 | + 'AVG(lcp) as avg_lcp', |
| 116 | + 'AVG(cls) as avg_cls', |
| 117 | + 'AVG(fid) as avg_fid', |
| 118 | + 'AVG(inp) as avg_inp', |
134 | 119 | 'COUNT(*) as pageviews' |
135 | 120 | ], |
136 | | - where: ['event_name = \'screen_view\'', 'os_name != \'\'', 'load_time > 0'], |
| 121 | + where: ["os_name != ''"], |
137 | 122 | groupBy: ['os_name'], |
138 | | - orderBy: 'avg_load_time DESC', |
| 123 | + orderBy: 'avg_lcp DESC', |
139 | 124 | limit: 100, |
140 | | - timeField: 'time', |
| 125 | + timeField: 'timestamp', |
141 | 126 | allowedFilters: ['path', 'device_type', 'browser_name'], |
142 | 127 | customizable: true |
143 | 128 | }, |
144 | 129 |
|
145 | 130 | performance_by_region: { |
146 | | - table: Analytics.events, |
| 131 | + table: Analytics.web_vitals, |
147 | 132 | fields: [ |
148 | | - 'CONCAT(region, \', \', country) as name', |
| 133 | + "CONCAT(region, ', ', country) as name", |
149 | 134 | 'COUNT(DISTINCT anonymous_id) as visitors', |
150 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
151 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
152 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
153 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
154 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
155 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
156 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 135 | + 'AVG(fcp) as avg_fcp', |
| 136 | + 'AVG(lcp) as avg_lcp', |
| 137 | + 'AVG(cls) as avg_cls', |
| 138 | + 'AVG(fid) as avg_fid', |
| 139 | + 'AVG(inp) as avg_inp', |
157 | 140 | 'COUNT(*) as pageviews' |
158 | 141 | ], |
159 | | - where: ['event_name = \'screen_view\'', 'region != \'\'', 'load_time > 0'], |
| 142 | + where: ["region != ''"], |
160 | 143 | groupBy: ['region', 'country'], |
161 | | - orderBy: 'avg_load_time DESC', |
| 144 | + orderBy: 'avg_lcp DESC', |
162 | 145 | limit: 100, |
163 | | - timeField: 'time', |
| 146 | + timeField: 'timestamp', |
164 | 147 | allowedFilters: ['path', 'device_type', 'browser_name'], |
165 | 148 | customizable: true |
166 | 149 | }, |
167 | 150 |
|
168 | 151 | performance_time_series: { |
169 | | - table: Analytics.events, |
| 152 | + table: Analytics.web_vitals, |
170 | 153 | fields: [ |
171 | | - 'toDate(time) as date', |
172 | | - 'AVG(CASE WHEN load_time > 0 THEN load_time ELSE NULL END) as avg_load_time', |
173 | | - 'AVG(CASE WHEN ttfb > 0 THEN ttfb ELSE NULL END) as avg_ttfb', |
174 | | - 'AVG(CASE WHEN dom_ready_time > 0 THEN dom_ready_time ELSE NULL END) as avg_dom_ready_time', |
175 | | - 'AVG(CASE WHEN render_time > 0 THEN render_time ELSE NULL END) as avg_render_time', |
176 | | - 'AVG(CASE WHEN fcp > 0 THEN fcp ELSE NULL END) as avg_fcp', |
177 | | - 'AVG(CASE WHEN lcp > 0 THEN lcp ELSE NULL END) as avg_lcp', |
178 | | - 'AVG(CASE WHEN cls >= 0 THEN cls ELSE NULL END) as avg_cls', |
| 154 | + 'toDate(timestamp) as date', |
| 155 | + 'AVG(fcp) as avg_fcp', |
| 156 | + 'AVG(lcp) as avg_lcp', |
| 157 | + 'AVG(cls) as avg_cls', |
| 158 | + 'AVG(fid) as avg_fid', |
| 159 | + 'AVG(inp) as avg_inp', |
179 | 160 | 'COUNT(*) as pageviews' |
180 | 161 | ], |
181 | | - where: ['event_name = \'screen_view\''], |
182 | | - groupBy: ['toDate(time)'], |
| 162 | + groupBy: ['toDate(timestamp)'], |
183 | 163 | orderBy: 'date ASC', |
184 | | - timeField: 'time', |
| 164 | + timeField: 'timestamp', |
185 | 165 | allowedFilters: ['path', 'device_type', 'browser_name'], |
186 | 166 | customizable: true |
187 | 167 | } |
|
0 commit comments