Skip to content

Commit 9029dc6

Browse files
burakguneliburak.gueneli
andauthored
Page Weight 2024 Queries (#3732)
* Queries of page-weight 2024 * Fix linter errors * Fix wrong css bytes name * CWV trend SQL implemented * Fix linter issues * fix cwv and css request type calculation --------- Co-authored-by: burak.gueneli <burak.gueneli@uberall.com>
1 parent ef9e375 commit 9029dc6

10 files changed

Lines changed: 289 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SELECT
2+
percentile,
3+
client,
4+
is_root_page,
5+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS total_kbytes,
6+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesHtml') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS html_kbytes,
7+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesJS') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS js_kbytes,
8+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesCss') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS css_kbytes,
9+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesImg') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS img_kbytes,
10+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesOther') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS other_kbytes,
11+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesHtmlDoc') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS html_doc_kbytes,
12+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesFont') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS font_kbytes
13+
FROM
14+
`httparchive.all.pages`,
15+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
16+
WHERE
17+
date = '2024-06-01'
18+
GROUP BY
19+
percentile,
20+
client,
21+
is_root_page
22+
ORDER BY
23+
client,
24+
is_root_page,
25+
percentile
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
SELECT
2+
client,
3+
is_root_page,
4+
COUNTIF(JSON_VALUE(lighthouse, '$.audits.uses-text-compression.score') IS NULL) AS null_count,
5+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.uses-text-compression.score') AS FLOAT64) >= 0.9) AS pass_count,
6+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.uses-text-compression.score') AS FLOAT64) < 0.9) AS fail_count,
7+
COUNT(0) AS total,
8+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.uses-text-compression.score') AS FLOAT64) >= 0.9) / COUNT(0) AS pct_pass,
9+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.uses-text-compression.score') AS FLOAT64) < 0.9) / COUNT(0) AS pct_fail
10+
FROM
11+
`httparchive.all.pages`
12+
WHERE
13+
date = '2024-06-01'
14+
GROUP BY
15+
client,
16+
is_root_page
17+
ORDER BY
18+
client,
19+
is_root_page,
20+
null_count,
21+
pass_count,
22+
fail_count

sql/2024/page-weight/cwv_trend.sql

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
WITH metrics_data AS (
2+
SELECT
3+
date,
4+
client,
5+
CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64) AS bytes_total,
6+
CAST(JSON_VALUE(lighthouse, '$.audits.largest-contentful-paint.numericValue') AS FLOAT64) AS lcp,
7+
CAST(JSON_VALUE(lighthouse, '$.audits.cumulative-layout-shift.numericValue') AS FLOAT64) AS cls,
8+
CAST(JSON_VALUE(lighthouse, '$.audits.total-blocking-time.numericValue') AS FLOAT64) AS tbt,
9+
CAST(JSON_VALUE(lighthouse, '$.audits.first-contentful-paint.numericValue') AS FLOAT64) AS fcp,
10+
CAST(JSON_VALUE(lighthouse, '$.audits.interactive.numericValue') AS FLOAT64) AS tti,
11+
CAST(JSON_VALUE(lighthouse, '$.categories.performance.score') AS FLOAT64) AS performance_score
12+
FROM
13+
`httparchive.all.pages`
14+
WHERE
15+
date >= '2023-06-01' AND
16+
date <= '2024-06-01' AND
17+
EXTRACT(DAY FROM date) = 1 -- Only include data from the first day of each month
18+
)
19+
SELECT
20+
date,
21+
client,
22+
COUNT(DISTINCT IF(bytes_total > 0, bytes_total, NULL)) AS total_pages,
23+
24+
-- Page Size metrics
25+
ROUND(APPROX_QUANTILES(bytes_total, 1000)[OFFSET(100)] / 1024, 2) AS p10_page_size_kb,
26+
ROUND(APPROX_QUANTILES(bytes_total, 1000)[OFFSET(250)] / 1024, 2) AS p25_page_size_kb,
27+
ROUND(APPROX_QUANTILES(bytes_total, 1000)[OFFSET(500)] / 1024, 2) AS p50_page_size_kb,
28+
ROUND(APPROX_QUANTILES(bytes_total, 1000)[OFFSET(750)] / 1024, 2) AS p75_page_size_kb,
29+
ROUND(APPROX_QUANTILES(bytes_total, 1000)[OFFSET(900)] / 1024, 2) AS p90_page_size_kb,
30+
31+
-- LCP metrics
32+
ROUND(APPROX_QUANTILES(lcp, 1000)[OFFSET(100)], 2) AS p10_lcp,
33+
ROUND(APPROX_QUANTILES(lcp, 1000)[OFFSET(250)], 2) AS p25_lcp,
34+
ROUND(APPROX_QUANTILES(lcp, 1000)[OFFSET(500)], 2) AS p50_lcp,
35+
ROUND(APPROX_QUANTILES(lcp, 1000)[OFFSET(750)], 2) AS p75_lcp,
36+
ROUND(APPROX_QUANTILES(lcp, 1000)[OFFSET(900)], 2) AS p90_lcp,
37+
38+
-- CLS metrics
39+
ROUND(APPROX_QUANTILES(cls, 1000)[OFFSET(100)], 3) AS p10_cls,
40+
ROUND(APPROX_QUANTILES(cls, 1000)[OFFSET(250)], 3) AS p25_cls,
41+
ROUND(APPROX_QUANTILES(cls, 1000)[OFFSET(500)], 3) AS p50_cls,
42+
ROUND(APPROX_QUANTILES(cls, 1000)[OFFSET(750)], 3) AS p75_cls,
43+
ROUND(APPROX_QUANTILES(cls, 1000)[OFFSET(900)], 3) AS p90_cls,
44+
45+
-- TBT metrics (as a proxy for FID)
46+
ROUND(APPROX_QUANTILES(tbt, 1000)[OFFSET(100)], 2) AS p10_tbt,
47+
ROUND(APPROX_QUANTILES(tbt, 1000)[OFFSET(250)], 2) AS p25_tbt,
48+
ROUND(APPROX_QUANTILES(tbt, 1000)[OFFSET(500)], 2) AS p50_tbt,
49+
ROUND(APPROX_QUANTILES(tbt, 1000)[OFFSET(750)], 2) AS p75_tbt,
50+
ROUND(APPROX_QUANTILES(tbt, 1000)[OFFSET(900)], 2) AS p90_tbt,
51+
52+
-- FCP metrics
53+
ROUND(APPROX_QUANTILES(fcp, 1000)[OFFSET(100)], 2) AS p10_fcp,
54+
ROUND(APPROX_QUANTILES(fcp, 1000)[OFFSET(250)], 2) AS p25_fcp,
55+
ROUND(APPROX_QUANTILES(fcp, 1000)[OFFSET(500)], 2) AS p50_fcp,
56+
ROUND(APPROX_QUANTILES(fcp, 1000)[OFFSET(750)], 2) AS p75_fcp,
57+
ROUND(APPROX_QUANTILES(fcp, 1000)[OFFSET(900)], 2) AS p90_fcp,
58+
59+
-- TTI metrics
60+
ROUND(APPROX_QUANTILES(tti, 1000)[OFFSET(100)], 2) AS p10_tti,
61+
ROUND(APPROX_QUANTILES(tti, 1000)[OFFSET(250)], 2) AS p25_tti,
62+
ROUND(APPROX_QUANTILES(tti, 1000)[OFFSET(500)], 2) AS p50_tti,
63+
ROUND(APPROX_QUANTILES(tti, 1000)[OFFSET(750)], 2) AS p75_tti,
64+
ROUND(APPROX_QUANTILES(tti, 1000)[OFFSET(900)], 2) AS p90_tti,
65+
66+
-- Performance Score metrics
67+
ROUND(APPROX_QUANTILES(performance_score, 1000)[OFFSET(900)] * 100, 2) AS p10_performance_score,
68+
ROUND(APPROX_QUANTILES(performance_score, 1000)[OFFSET(750)] * 100, 2) AS p25_performance_score,
69+
ROUND(APPROX_QUANTILES(performance_score, 1000)[OFFSET(500)] * 100, 2) AS p50_performance_score,
70+
ROUND(APPROX_QUANTILES(performance_score, 1000)[OFFSET(250)] * 100, 2) AS p75_performance_score,
71+
ROUND(APPROX_QUANTILES(performance_score, 1000)[OFFSET(100)] * 100, 2) AS p90_performance_score,
72+
73+
-- Good CWV percentages
74+
ROUND(COUNTIF(lcp <= 2500) / COUNT(0) * 100, 2) AS good_lcp_percent,
75+
ROUND(COUNTIF(cls <= 0.1) / COUNT(0) * 100, 2) AS good_cls_percent,
76+
ROUND(COUNTIF(tbt <= 300) / COUNT(0) * 100, 2) AS good_tbt_percent,
77+
ROUND(COUNTIF(fcp <= 1800) / COUNT(0) * 100, 2) AS good_fcp_percent
78+
79+
FROM
80+
metrics_data
81+
GROUP BY
82+
date,
83+
client
84+
ORDER BY
85+
date DESC,
86+
client
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
SELECT
2+
client,
3+
is_root_page,
4+
COUNTIF(JSON_VALUE(lighthouse, '$.audits.third-party-facades.score') IS NULL) AS null_count,
5+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.third-party-facades.score') AS FLOAT64) >= 0.9) AS pass_count,
6+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.third-party-facades.score') AS FLOAT64) < 0.9) AS fail_count,
7+
COUNT(0) AS total,
8+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.third-party-facades.score') AS FLOAT64) >= 0.9) / COUNT(0) AS pct_pass,
9+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.third-party-facades.score') AS FLOAT64) < 0.9) / COUNT(0) AS pct_fail
10+
FROM
11+
`httparchive.all.pages`
12+
WHERE
13+
date = '2024-06-01'
14+
GROUP BY
15+
client,
16+
is_root_page
17+
ORDER BY
18+
client,
19+
is_root_page,
20+
null_count,
21+
pass_count,
22+
fail_count
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
SELECT
2+
client,
3+
is_root_page,
4+
COUNTIF(JSON_VALUE(lighthouse, '$.audits.unminified-css.score') IS NULL) AS null_count,
5+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-css.score') AS FLOAT64) >= 0.9) AS pass_count,
6+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-css.score') AS FLOAT64) < 0.9) AS fail_count,
7+
COUNT(0) AS total,
8+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-css.score') AS FLOAT64) >= 0.9) / COUNT(0) AS pct_pass,
9+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-css.score') AS FLOAT64) < 0.9) / COUNT(0) AS pct_fail
10+
FROM
11+
`httparchive.all.pages`
12+
WHERE
13+
date = '2024-06-01'
14+
GROUP BY
15+
client,
16+
is_root_page
17+
ORDER BY
18+
client,
19+
is_root_page,
20+
null_count,
21+
pass_count,
22+
fail_count
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
SELECT
2+
client,
3+
is_root_page,
4+
COUNTIF(JSON_VALUE(lighthouse, '$.audits.unminified-javascript.score') IS NULL) AS null_count,
5+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-javascript.score') AS FLOAT64) >= 0.9) AS pass_count,
6+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-javascript.score') AS FLOAT64) < 0.9) AS fail_count,
7+
COUNT(0) AS total,
8+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-javascript.score') AS FLOAT64) >= 0.9) / COUNT(0) AS pct_pass,
9+
COUNTIF(SAFE_CAST(JSON_VALUE(lighthouse, '$.audits.unminified-javascript.score') AS FLOAT64) < 0.9) / COUNT(0) AS pct_fail
10+
FROM
11+
`httparchive.all.pages`
12+
WHERE
13+
date = '2024-06-01'
14+
GROUP BY
15+
client,
16+
is_root_page
17+
ORDER BY
18+
client,
19+
is_root_page,
20+
null_count,
21+
pass_count,
22+
fail_count
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SELECT
2+
date,
3+
client,
4+
is_root_page,
5+
ROUND(APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64), 1000)[OFFSET(100)] / 1024, 2) AS p10,
6+
ROUND(APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64), 1000)[OFFSET(250)] / 1024, 2) AS p25,
7+
ROUND(APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64), 1000)[OFFSET(500)] / 1024, 2) AS p50,
8+
ROUND(APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64), 1000)[OFFSET(750)] / 1024, 2) AS p75,
9+
ROUND(APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64), 1000)[OFFSET(900)] / 1024, 2) AS p90
10+
FROM
11+
`httparchive.all.pages`
12+
WHERE
13+
date >= '2023-06-01' AND date <= '2024-06-01' AND -- Adjust this range as needed
14+
CAST(JSON_VALUE(summary, '$.bytesTotal') AS INT64) > 0 AND
15+
EXTRACT(DAY FROM date) = 1 -- Only include data from the first day of each month
16+
GROUP BY
17+
date,
18+
client,
19+
is_root_page
20+
ORDER BY
21+
date DESC,
22+
client,
23+
is_root_page
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SELECT
2+
percentile,
3+
client,
4+
is_root_page,
5+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqTotal') AS INT64), 1000)[OFFSET(percentile * 10)] AS total_req,
6+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqHtml') AS INT64), 1000)[OFFSET(percentile * 10)] AS html_req,
7+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqJS') AS INT64), 1000)[OFFSET(percentile * 10)] AS js_req,
8+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqCss') AS INT64), 1000)[OFFSET(percentile * 10)] AS css_req,
9+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqImg') AS INT64), 1000)[OFFSET(percentile * 10)] AS img_req,
10+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqJson') AS INT64), 1000)[OFFSET(percentile * 10)] AS json_req,
11+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqOther') AS INT64), 1000)[OFFSET(percentile * 10)] AS other_req,
12+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.reqFont') AS INT64), 1000)[OFFSET(percentile * 10)] AS font_req
13+
FROM
14+
`httparchive.all.pages`,
15+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
16+
WHERE
17+
date = '2024-06-01' -- Adjust this date as needed
18+
GROUP BY
19+
percentile,
20+
client,
21+
is_root_page
22+
ORDER BY
23+
client,
24+
is_root_page,
25+
percentile
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT
2+
client,
3+
percentile,
4+
CAST(JSON_VALUE(summary, '$.type') AS STRING) AS format,
5+
is_root_page,
6+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.respBodySize') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS resp_size
7+
FROM
8+
`httparchive.all.requests`,
9+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
10+
WHERE
11+
date = '2024-06-01' -- Adjust this date as needed
12+
GROUP BY
13+
client,
14+
percentile,
15+
format,
16+
is_root_page
17+
ORDER BY
18+
format,
19+
client,
20+
is_root_page,
21+
percentile
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT
2+
client,
3+
percentile,
4+
CAST(JSON_VALUE(summary, '$.type') AS STRING) AS type,
5+
is_root_page,
6+
APPROX_QUANTILES(CAST(JSON_VALUE(summary, '$.respSize') AS INT64) / 1024, 1000)[OFFSET(percentile * 10)] AS resp_size
7+
FROM
8+
`httparchive.all.requests`,
9+
UNNEST([10, 25, 50, 75, 90, 100]) AS percentile
10+
WHERE
11+
date = '2024-06-01' -- Adjust this date as needed
12+
GROUP BY
13+
client,
14+
percentile,
15+
type,
16+
is_root_page
17+
ORDER BY
18+
client,
19+
type,
20+
is_root_page,
21+
percentile

0 commit comments

Comments
 (0)