-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathrelated_origin_trials_top.sql
More file actions
114 lines (105 loc) · 2.73 KB
/
related_origin_trials_top.sql
File metadata and controls
114 lines (105 loc) · 2.73 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
-- noqa: disable=PRS
-- Pages that participate in the privacy-relayed origin trials
CREATE TEMP FUNCTION `PARSE_ORIGIN_TRIAL`(token STRING) RETURNS STRUCT<
token STRING,
origin STRING,
feature STRING,
expiry TIMESTAMP,
is_subdomain BOOL,
is_third_party BOOL
>
DETERMINISTIC AS (
(
WITH decoded_token AS (
SELECT SAFE_CONVERT_BYTES_TO_STRING(SUBSTR(SAFE.FROM_BASE64(token), 70)) AS decoded
)
SELECT
STRUCT(
decoded AS token,
JSON_VALUE(decoded, '$.origin') AS origin,
JSON_VALUE(decoded, '$.feature') AS feature,
TIMESTAMP_SECONDS(CAST(JSON_VALUE(decoded, '$.expiry') AS INT64)) AS expiry,
JSON_VALUE(decoded, '$.isSubdomain') = 'true' AS is_subdomain,
JSON_VALUE(decoded, '$.isThirdParty') = 'true' AS is_third_party
)
FROM decoded_token
)
);
WITH base_totals AS (
SELECT
client,
COUNT(DISTINCT root_page) AS total_websites
FROM `httparchive.crawl.pages`
WHERE
date = '2025-07-01'
GROUP BY client
),
pages AS (
SELECT
client,
root_page,
custom_metrics.other.`origin-trials` AS ot_metrics,
custom_metrics.other.almanac AS almanac_metrics
FROM `httparchive.crawl.pages`
WHERE
date = '2025-07-01'
),
response_headers AS (
SELECT
client,
root_page,
PARSE_ORIGIN_TRIAL(response_header.value) AS ot
FROM `httparchive.crawl.requests`,
UNNEST(response_headers) response_header
WHERE
date = '2025-07-01' AND
is_main_document = TRUE AND
LOWER(response_header.name) = 'origin-trial'
),
meta_tags AS (
SELECT
client,
root_page,
PARSE_ORIGIN_TRIAL(SAFE.STRING(meta_node.content)) AS ot
FROM pages,
UNNEST(JSON_QUERY_ARRAY(almanac_metrics.`meta-nodes`.nodes)) meta_node
WHERE
LOWER(SAFE.STRING(meta_node.`http-equiv`)) = 'origin-trial'
),
ot_from_custom_metric AS (
SELECT
client,
root_page,
PARSE_ORIGIN_TRIAL(SAFE.STRING(metric.token)) AS ot
FROM pages,
UNNEST(JSON_QUERY_ARRAY(ot_metrics)) metric
),
aggregated AS (
SELECT
client,
ot.feature,
--ot.expiry >= CURRENT_TIMESTAMP() AS is_active,
COUNT(DISTINCT root_page) AS number_of_websites
FROM (
SELECT * FROM response_headers
UNION ALL
SELECT * FROM meta_tags
UNION ALL
SELECT * FROM ot_from_custom_metric
)
GROUP BY
client,
feature
--is_active
)
FROM aggregated
|> JOIN base_totals USING (client)
|> EXTEND number_of_websites / total_websites AS pct_websites
|> DROP total_websites
|> 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