Created
September 3, 2020 17:11
-
-
Save rviscomi/2a700be90446643e0cf43c639b9919de to your computer and use it in GitHub Desktop.
Calculating the % of Gatsby websites with "good" Core Web Vitals performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#standardSQL | |
# Gatsby Core Web Vitals performance | |
CREATE TEMP FUNCTION IS_GOOD (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS ( | |
good / (good + needs_improvement + poor) >= 0.75 | |
); | |
CREATE TEMP FUNCTION IS_NON_ZERO (good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS ( | |
good + needs_improvement + poor > 0 | |
); | |
SELECT | |
app, | |
COUNT(DISTINCT origin) AS origins, | |
# Origins with good LCP divided by origins with any LCP. | |
SAFE_DIVIDE( | |
COUNT(DISTINCT IF(IS_GOOD(fast_lcp, avg_lcp, slow_lcp), origin, NULL)), | |
COUNT(DISTINCT IF(IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp), origin, NULL))) AS pct_good_lcp, | |
# Origins with good FID divided by origins with any FID. | |
SAFE_DIVIDE( | |
COUNT(DISTINCT IF(IS_GOOD(fast_fid, avg_fid, slow_fid), origin, NULL)), | |
COUNT(DISTINCT IF(IS_NON_ZERO(fast_fid, avg_fid, slow_fid), origin, NULL))) AS pct_good_fid, | |
# Origins with good CLS divided by origins with any CLS. | |
SAFE_DIVIDE( | |
COUNT(DISTINCT IF(IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)), | |
COUNT(DISTINCT IF(IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))) AS pct_good_cls, | |
# Origins with good LCP, FID, and CLS dividied by origins with any LCP, FID, and CLS. | |
SAFE_DIVIDE( | |
COUNT(DISTINCT IF( | |
IS_GOOD(fast_lcp, avg_lcp, slow_lcp) AND | |
IS_GOOD(fast_fid, avg_fid, slow_fid) AND | |
IS_GOOD(small_cls, medium_cls, large_cls), origin, NULL)), | |
COUNT(DISTINCT IF( | |
IS_NON_ZERO(fast_lcp, avg_lcp, slow_lcp) AND | |
IS_NON_ZERO(fast_fid, avg_fid, slow_fid) AND | |
IS_NON_ZERO(small_cls, medium_cls, large_cls), origin, NULL))) AS pct_good_cwv | |
FROM | |
`chrome-ux-report.materialized.metrics_summary` | |
JOIN ( | |
SELECT | |
url, | |
app | |
FROM | |
`httparchive.technologies.2019_08_01_*` | |
WHERE | |
app IN ('Gatsby') | |
GROUP BY | |
url, | |
app) | |
ON | |
CONCAT(origin, '/') = url | |
WHERE | |
# The CrUX 202008 dataset is not available until September 8. | |
date = '2020-07-01' | |
GROUP BY | |
app | |
ORDER BY | |
origins DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment