Created
January 23, 2021 03:30
-
-
Save jefrydco/44997119f62d920a612102b0fcddfc22 to your computer and use it in GitHub Desktop.
Calculate the percent of origins that comply with each Core Web Vital's "good" threshold for 75% or more of experiences for Indonesia country.
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 | |
# This query processes 735.9 MB. | |
# Calculate the percent of origins that comply with each Core Web Vital's "good" threshold for 75% or more of experiences. | |
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 | |
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.country_summary` | |
WHERE | |
country_code = 'id' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://github.com/GoogleChrome/CrUX/blob/master/sql/core-web-vitals-compliance-rates.sql
How to Run