Skip to content

Commit b92ab90

Browse files
authored
Add SQL query for custom property adoption analysis
1 parent e1be187 commit b92ab90

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#standardSQL
2+
# % of sites that use custom properties.
3+
# Same query as 2019, to compare trend
4+
CREATE TEMPORARY FUNCTION usesCustomProps(css JSON)
5+
RETURNS BOOLEAN LANGUAGE js AS '''
6+
try {
7+
var reduceValues = (values, rule) => {
8+
if ('rules' in rule) {
9+
return rule.rules.reduce(reduceValues, values);
10+
}
11+
if (!('declarations' in rule)) {
12+
return values;
13+
}
14+
15+
return values.concat(rule.declarations.filter(d => d.property.startsWith(`--`)));
16+
};
17+
return css.stylesheet.rules.reduce(reduceValues, []).length > 0;
18+
} catch (e) {
19+
return false;
20+
}
21+
''';
22+
23+
SELECT
24+
client,
25+
COUNTIF(num_stylesheets > 0) AS freq,
26+
total,
27+
COUNTIF(num_stylesheets > 0) / total AS pct
28+
FROM (
29+
SELECT
30+
client,
31+
page,
32+
COUNTIF(usesCustomProps(css)) AS num_stylesheets
33+
FROM
34+
`httparchive.crawl.parsed_css`
35+
WHERE
36+
date = '2025-07-01' AND
37+
rank <= 1000000 AND
38+
is_root_page -- remove if wanna look at home pages AND inner pages. Old tables only had home pages.
39+
GROUP BY
40+
client,
41+
page
42+
)
43+
JOIN (
44+
SELECT
45+
client,
46+
COUNT(0) AS total
47+
FROM
48+
`httparchive.crawl.pages`
49+
WHERE
50+
date = '2025-07-01' AND
51+
rank <= 1000000 AND
52+
is_root_page -- remove if wanna look at home pages AND inner pages. Old tables only had home pages.
53+
GROUP BY
54+
client
55+
)
56+
USING (client)
57+
GROUP BY
58+
client,
59+
total

0 commit comments

Comments
 (0)