-
-
Notifications
You must be signed in to change notification settings - Fork 169
/
custom_property_adoption.sql
47 lines (45 loc) · 1.05 KB
/
custom_property_adoption.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#standardSQL
# % of sites that use custom properties.
# Same query as 2019, to compare trend
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,
COUNTIF(num_stylesheets > 0) / total AS pct
FROM (
SELECT
client,
page,
COUNTIF(usesCustomProps(css)) AS num_stylesheets
FROM
`httparchive.almanac.parsed_css`
WHERE
date = '2021-07-01'
GROUP BY
client,
page)
JOIN
(SELECT _TABLE_SUFFIX AS client, COUNT(0) AS total FROM `httparchive.summary_pages.2021_07_01_*` GROUP BY client)
USING
(client)
GROUP BY
client,
total