-
-
Save rviscomi/71328c6b395f377e7d7f6c7be5ab6da7 to your computer and use it in GitHub Desktop.
Reusing the 2019 approach to detecting custom property adoption, the results are: 14.47% desktop and 19.29% mobile. Using the new "css-variables" custom metric, the results are: 27.27% desktop and 26.50% mobile.
This file contains 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 | |
# 02_01: % of sites that use custom properties. | |
CREATE TEMPORARY FUNCTION usesCustomProps(css STRING) | |
RETURNS BOOLEAN LANGUAGE js AS ''' | |
try { | |
var reduceValues = (values, rule) => { | |
if ('rules' in rule) { | |
return rule.rules.reduce(reduceValues, values); | |
} | |
if (!('declarations' in rule)) { | |
return values; | |
} | |
return values.concat(rule.declarations.filter(d => d.property.startsWith(`--`))); | |
}; | |
var $ = JSON.parse(css); | |
return $.stylesheet.rules.reduce(reduceValues, []).length > 0; | |
} catch (e) { | |
return false; | |
} | |
'''; | |
SELECT | |
client, | |
COUNTIF(num_stylesheets > 0) AS freq, | |
total, | |
ROUND(COUNTIF(num_stylesheets > 0) * 100 / total, 2) AS pct | |
FROM ( | |
SELECT | |
client, | |
page, | |
COUNTIF(usesCustomProps(css)) AS num_stylesheets | |
FROM | |
`httparchive.almanac.parsed_css` | |
WHERE | |
date = '2020-08-01' | |
GROUP BY | |
client, | |
page) | |
JOIN | |
(SELECT _TABLE_SUFFIX AS client, COUNT(0) AS total FROM `httparchive.summary_pages.2020_08_01_*` GROUP BY client) | |
USING | |
(client) | |
GROUP BY | |
client, | |
total |
This file contains 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 | |
# Percent of pages that use custom properties. | |
CREATE TEMPORARY FUNCTION getCustomPropertyCount(payload STRING) RETURNS INT64 LANGUAGE js AS ''' | |
try { | |
var $ = JSON.parse(payload); | |
var vars = JSON.parse($['_css-variables']); | |
return Object.values(vars.summary).length; | |
} catch (e) { | |
return 0; | |
} | |
'''; | |
SELECT | |
client, | |
COUNTIF(has_custom_properties) AS freq, | |
total, | |
COUNTIF(has_custom_properties) / total AS pct | |
FROM ( | |
SELECT | |
_TABLE_SUFFIX AS client, | |
getCustomPropertyCount(payload) > 0 AS has_custom_properties | |
FROM | |
`httparchive.pages.2020_08_01_*`) | |
JOIN ( | |
SELECT | |
_TABLE_SUFFIX AS client, | |
COUNT(DISTINCT url) AS total | |
FROM | |
`httparchive.pages.2020_08_01_*` | |
GROUP BY | |
_TABLE_SUFFIX) | |
USING (client) | |
GROUP BY | |
client, | |
total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment