1
1
# standardSQL
2
2
-- Core web vitals by Shopify theme
3
- CREATE TEMP FUNCTION IS_GOOD (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
3
+ CREATE TEMP FUNCTION IS_GOOD(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
4
4
good / (good + needs_improvement + poor) >= 0 .75
5
5
);
6
6
7
- CREATE TEMP FUNCTION IS_POOR (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
7
+ CREATE TEMP FUNCTION IS_POOR(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
8
8
poor / (good + needs_improvement + poor) > 0 .25
9
9
);
10
10
11
- CREATE TEMP FUNCTION IS_NON_ZERO (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
11
+ CREATE TEMP FUNCTION IS_NON_ZERO(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
12
12
good + needs_improvement + poor > 0
13
13
);
14
14
15
15
-- All Shopify shops in HTTPArchive
16
16
WITH archive_pages AS (
17
- SELECT
18
- client,
19
- page AS url,
20
- JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.name' ) AS theme_name,
21
- JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.theme_store_id' ) AS theme_store_id,
22
- FROM
23
- ` httparchive.all.pages`
24
- WHERE
25
- date = DATE (REPLACE(' ${YYYY_MM_DD}' , ' _' , ' -' )) AND
26
- is_root_page AND
27
- JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.name' ) IS NOT NULL -- first grab all shops for market share
17
+ SELECT
18
+ client,
19
+ page AS url,
20
+ JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.name' ) AS theme_name,
21
+ JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.theme_store_id' ) AS theme_store_id
22
+ FROM
23
+ ` httparchive.all.pages`
24
+ WHERE
25
+ date = DATE (REPLACE(' ${YYYY_MM_DD}' , ' _' , ' -' )) AND
26
+ is_root_page AND
27
+ JSON_VALUE(custom_metrics, ' $.ecommerce.Shopify.theme.name' ) IS NOT NULL -- first grab all shops for market share
28
28
)
29
29
30
30
SELECT
@@ -35,120 +35,138 @@ SELECT
35
35
-- Origins with good LCP divided by origins with any LCP.
36
36
SAFE_DIVIDE(
37
37
COUNT (DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
38
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL ))) AS pct_good_lcp,
38
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL ))
39
+ ) AS pct_good_lcp,
39
40
-- Origins with needs improvement are anything not good, nor poor.
40
41
1 -
41
- SAFE_DIVIDE(
42
- COUNT (DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
43
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL )))
44
- -
45
- SAFE_DIVIDE(
46
- COUNT (DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
47
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL )))
42
+ SAFE_DIVIDE(
43
+ COUNT (DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
44
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL ))
45
+ )
46
+ -
47
+ SAFE_DIVIDE(
48
+ COUNT (DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
49
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL )))
48
50
AS pct_ni_lcp,
49
51
-- Origins with poor LCP divided by origins with any LCP.
50
52
SAFE_DIVIDE(
51
53
COUNT (DISTINCT IF(IS_POOR(fast_lcp, avg_lcp, slow_lcp), origin, NULL )),
52
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL ))) AS pct_poor_lcp,
54
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL ))
55
+ ) AS pct_poor_lcp,
53
56
54
57
-- Origins with good TTFB divided by origins with any TTFB.
55
58
SAFE_DIVIDE(
56
59
COUNT (DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
57
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL ))) AS pct_good_ttfb,
60
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL ))
61
+ ) AS pct_good_ttfb,
58
62
-- Origins with needs improvement are anything not good, nor poor.
59
63
1 -
60
- SAFE_DIVIDE(
61
- COUNT (DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
62
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )))
63
- -
64
- SAFE_DIVIDE(
65
- COUNT (DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
66
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )))
64
+ SAFE_DIVIDE(
65
+ COUNT (DISTINCT IF(IS_GOOD(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
66
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL ))
67
+ )
68
+ -
69
+ SAFE_DIVIDE(
70
+ COUNT (DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
71
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )))
67
72
AS pct_ni_ttfb,
68
73
-- Origins with poor TTFB divided by origins with any TTFB.
69
74
SAFE_DIVIDE(
70
75
COUNT (DISTINCT IF(IS_POOR(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL )),
71
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL ))) AS pct_poor_ttfb,
76
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_ttfb, avg_ttfb, slow_ttfb), origin, NULL ))
77
+ ) AS pct_poor_ttfb,
72
78
73
- -- Origins with good FCP divided by origins with any FCP.
79
+ -- Origins with good FCP divided by origins with any FCP.
74
80
SAFE_DIVIDE(
75
81
COUNT (DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
76
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL ))) AS pct_good_fcp,
82
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL ))
83
+ ) AS pct_good_fcp,
77
84
-- Origins with needs improvement are anything not good, nor poor.
78
85
1 -
79
- SAFE_DIVIDE(
80
- COUNT (DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
81
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL )))
82
- -
83
- SAFE_DIVIDE(
84
- COUNT (DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
85
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL )))
86
+ SAFE_DIVIDE(
87
+ COUNT (DISTINCT IF(IS_GOOD(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
88
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL ))
89
+ )
90
+ -
91
+ SAFE_DIVIDE(
92
+ COUNT (DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
93
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL )))
86
94
AS pct_ni_fcp,
87
95
-- Origins with poor FCP divided by origins with any FCP.
88
96
SAFE_DIVIDE(
89
97
COUNT (DISTINCT IF(IS_POOR(fast_fcp, avg_fcp, slow_fcp), origin, NULL )),
90
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL ))) AS pct_poor_fcp,
98
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_fcp, avg_fcp, slow_fcp), origin, NULL ))
99
+ ) AS pct_poor_fcp,
91
100
92
101
-- Origins with good INP divided by origins with any INP.
93
102
SAFE_DIVIDE(
94
103
COUNT (DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL )),
95
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL ))) AS pct_good_inp,
104
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL ))
105
+ ) AS pct_good_inp,
96
106
-- Origins with needs improvement are anything not good, nor poor.
97
107
1 -
98
- SAFE_DIVIDE(
99
- COUNT (DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL )),
100
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL )))
101
- -
102
- SAFE_DIVIDE(
103
- COUNT (DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL )),
104
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL )))
108
+ SAFE_DIVIDE(
109
+ COUNT (DISTINCT IF(IS_GOOD(fast_inp, avg_inp, slow_inp), origin, NULL )),
110
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL ))
111
+ )
112
+ -
113
+ SAFE_DIVIDE(
114
+ COUNT (DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL )),
115
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL )))
105
116
AS pct_ni_inp,
106
117
-- Origins with poor INP divided by origins with any INP.
107
118
SAFE_DIVIDE(
108
119
COUNT (DISTINCT IF(IS_POOR(fast_inp, avg_inp, slow_inp), origin, NULL )),
109
- COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL ))) AS pct_poor_inp,
120
+ COUNT (DISTINCT IF(IS_NON_ZERO(fast_inp, avg_inp, slow_inp), origin, NULL ))
121
+ ) AS pct_poor_inp,
110
122
111
123
-- Origins with good CLS divided by origins with any CLS.
112
124
SAFE_DIVIDE(
113
125
COUNT (DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL )),
114
- COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))) AS pct_good_cls,
126
+ COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))
127
+ ) AS pct_good_cls,
115
128
-- Origins with needs improvement are anything not good, nor poor.
116
129
1 -
117
- SAFE_DIVIDE(
118
- COUNT (DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL )),
119
- COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL )))
120
- -
121
- SAFE_DIVIDE(
122
- COUNT (DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL )),
123
- COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL )))
130
+ SAFE_DIVIDE(
131
+ COUNT (DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL )),
132
+ COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))
133
+ )
134
+ -
135
+ SAFE_DIVIDE(
136
+ COUNT (DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL )),
137
+ COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL )))
124
138
AS pct_ni_cls,
125
139
-- Origins with poor CLS divided by origins with any CLS.
126
140
SAFE_DIVIDE(
127
141
COUNT (DISTINCT IF(IS_POOR(small_cls, medium_cls, large_cls), origin, NULL )),
128
- COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))) AS pct_poor_cls,
142
+ COUNT (DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))
143
+ ) AS pct_poor_cls,
129
144
130
145
-- Origins with good LCP, INP (optional), and CLS divided by origins with any LCP and CLS.
131
146
SAFE_DIVIDE(
132
147
COUNT (DISTINCT IF(
133
148
IS_GOOD(fast_lcp, avg_lcp, slow_lcp) AND
134
149
IS_GOOD(fast_inp, avg_inp, slow_inp) IS NOT FALSE AND
135
- IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL )),
150
+ IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL
151
+ )),
136
152
COUNT (DISTINCT IF(
137
153
IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp) AND
138
- IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL ))) AS pct_good_cwv
154
+ IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL
155
+ ))
156
+ ) AS pct_good_cwv
139
157
FROM
140
158
` chrome-ux-report.materialized.device_summary`
141
159
JOIN archive_pages
142
160
ON
143
161
CONCAT(origin, ' /' ) = url AND
144
162
IF(device = ' desktop' , ' desktop' , ' mobile' ) = client
145
163
JOIN (
146
- -- Add in top theme name for a theme store id as this should usually be the real theme name
164
+ -- Add in top theme name for a theme store id AS this should usually be the real theme name
147
165
SELECT
148
- COUNT (DISTINCT url) as pages_count,
166
+ COUNT (DISTINCT url) AS pages_count,
149
167
theme_store_id,
150
168
theme_name,
151
- row_number() over (partition by theme_store_id order by COUNT (DISTINCT url) desc ) as rank
169
+ row_number() OVER (PARTITION BY theme_store_id ORDER BY COUNT (DISTINCT url) DESC ) AS rank
152
170
FROM archive_pages
153
171
GROUP BY
154
172
theme_store_id,
0 commit comments