-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy paththird_parties_using_legacy_javascript.sql
More file actions
56 lines (51 loc) · 1.17 KB
/
third_parties_using_legacy_javascript.sql
File metadata and controls
56 lines (51 loc) · 1.17 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
#standardSQL
# Third-parties that use legacy JavaScript
CREATE TEMPORARY FUNCTION
getUrls(audit STRING)
RETURNS ARRAY<STRUCT<url STRING>> LANGUAGE js AS '''
try {
var $ = JSON.parse(audit);
return $.details.items.map(i => ({url: i.url}));
} catch(e) {
return [];
}
''';
WITH third_party_domains AS (
SELECT DISTINCT
NET.HOST(domain) AS domain
FROM
`httparchive.almanac.third_parties`
),
base AS (
SELECT
client,
page,
COUNTIF(third_party_domains.domain IS NULL) / COUNT(0) AS pct_1p_legacy,
COUNTIF(third_party_domains.domain IS NOT NULL) / COUNT(0) AS pct_3p_legacy
FROM (
SELECT
_TABLE_SUFFIX AS client,
NET.HOST(data.url) AS domain,
lighthouse.url AS page
FROM
`httparchive.lighthouse.2022_06_01_*` AS lighthouse,
UNNEST(getUrls(JSON_EXTRACT(report, "$.audits['legacy-javascript']"))) AS data
) AS potential_third_parties
LEFT OUTER JOIN
third_party_domains
ON
potential_third_parties.domain = third_party_domains.domain
GROUP BY
client,
page
)
SELECT
client,
AVG(pct_1p_legacy) AS avg_pct_1p_legacy,
AVG(pct_3p_legacy) AS avg_pct_3p_legacy
FROM
base
GROUP BY
client
ORDER BY
client