-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathcookies_first_party_top.sql
More file actions
27 lines (26 loc) · 1.05 KB
/
cookies_first_party_top.sql
File metadata and controls
27 lines (26 loc) · 1.05 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
/* Most common cookie names, by number of domains on which they appear.
Goal is to identify common trackers that use first-party cookies across sites.
*/
FROM `httparchive.crawl.pages`
|> WHERE date = '2025-07-01' -- AND rank = 1000
|> EXTEND COUNT(DISTINCT NET.HOST(root_page)) OVER (PARTITION BY client) AS total_domains
|> JOIN UNNEST(JSON_QUERY_ARRAY(custom_metrics.cookies)) AS cookie
|> EXTEND
NET.HOST(root_page) AS firstparty_domain,
NET.HOST(SAFE.STRING(cookie.domain)) AS cookie_domain,
SAFE.STRING(cookie.name) AS cookie_name
|> WHERE ENDS_WITH('.' || firstparty_domain, '.' || cookie_domain)
|> AGGREGATE
COUNT(DISTINCT firstparty_domain) AS domain_count,
COUNT(DISTINCT firstparty_domain) / ANY_VALUE(total_domains) AS pct_domains
GROUP BY client, cookie_name
|> PIVOT (
ANY_VALUE(domain_count) AS domain_count,
ANY_VALUE(pct_domains) AS pct_domains
FOR client IN ('desktop', 'mobile')
)
|> RENAME
pct_domains_mobile AS mobile,
pct_domains_desktop AS desktop
|> ORDER BY COALESCE(domain_count_mobile, 0) + COALESCE(domain_count_desktop, 0) DESC
|> LIMIT 1000