-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathclient_hints_top.sql
More file actions
44 lines (40 loc) · 1.6 KB
/
client_hints_top.sql
File metadata and controls
44 lines (40 loc) · 1.6 KB
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
-- noqa: disable=PRS
WITH totals AS (
FROM `httparchive.crawl.pages`
|> WHERE date = '2025-07-01' AND is_root_page --AND rank = 1000
|> AGGREGATE COUNT(*) AS total_websites GROUP BY client
),
/* Get Accept-CH Headers */
headers AS (
FROM `httparchive.crawl.requests`
|> WHERE date = '2025-07-01' AND is_root_page AND is_main_document --AND rank = 1000
|> JOIN UNNEST(response_headers) AS header
|> WHERE LOWER(header.name) = 'accept-ch'
|> LEFT JOIN UNNEST(SPLIT(LOWER(header.value), ',')) AS header_value
|> SELECT client, root_page, header_value
),
/* Get Accept-CH Meta Tags */
meta_tags AS (
FROM `httparchive.crawl.pages`
|> WHERE date = '2025-07-01' AND is_root_page --AND rank = 1000
|> JOIN UNNEST(JSON_QUERY_ARRAY(custom_metrics.other.almanac.`meta-nodes`.nodes)) AS meta_node
|> EXTEND LOWER(SAFE.STRING(meta_node.`http-equiv`)) AS tag_name
|> WHERE tag_name = 'accept-ch'
|> LEFT JOIN UNNEST(SPLIT(LOWER(SAFE.STRING(meta_node.content)), ',')) AS tag_value
|> SELECT client, root_page, tag_value
)
FROM headers
|> FULL OUTER JOIN meta_tags USING (client, root_page)
|> JOIN totals USING (client)
|> EXTEND TRIM(COALESCE(header_value, tag_value)) AS value
|> AGGREGATE
COUNT(DISTINCT root_page) AS number_of_websites,
COUNT(DISTINCT root_page) / ANY_VALUE(total_websites) AS pct_websites
GROUP BY client, value
|> PIVOT(
ANY_VALUE(number_of_websites) AS websites_count,
ANY_VALUE(pct_websites) AS pct
FOR client IN ('desktop', 'mobile')
)
|> RENAME pct_mobile AS mobile, pct_desktop AS desktop
|> ORDER BY COALESCE(websites_count_desktop, 0) + COALESCE(websites_count_mobile, 0) DESC