Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privacy - IAB Global Privacy Platform #138

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions dist/privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ return JSON.stringify({
iab_tcf_v1: (() => {
let consentData = {
present: typeof window.__cmp == 'function',
data: null,
compliant_setup: null,
};
// description of `__cmp`: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/CMP%20JS%20API%20v1.1%20Final.md#what-api-will-need-to-be-provided-by-the-cmp-
try {
Expand Down Expand Up @@ -151,13 +149,11 @@ return JSON.stringify({

/**
* IAB Transparency and Consent Framework v2
* docs v2: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2
* https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2
*/
iab_tcf_v2: (() => {
let tcData = {
present: typeof window.__tcfapi == 'function',
data: null,
compliant_setup: null,
};
// description of `__tcfapi`: https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#how-does-the-cmp-provide-the-api
try {
Expand Down Expand Up @@ -186,14 +182,34 @@ return JSON.stringify({
}
})(),

/**
* Global Privacy Platfrom (GPP)
* https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform
*/
iab_gpp: (() => {
let gppData = {
present: typeof window.__gpp == 'function',
};
try {
if (gppData.present) {
window.__gpp('ping', (result, success) => {
if (success) {
gppData.data = result;
}
});
}
} finally {
return gppData;
}
})(),

/**
* IAB US Privacy User Signal Mechanism “USP API”
* https://github.com/InteractiveAdvertisingBureau/USPrivacy
*/
iab_usp: (() => {
let uspData = {
present: typeof window.__uspapi == 'function',
privacy_string: null,
};
try {
if (uspData.present) {
Expand Down Expand Up @@ -485,10 +501,14 @@ return JSON.stringify({
return allowedCCPALinkPhrases.some(phrase => text.includes(phrase)) && !CCPAExclusionPhrases.some(phrase => text.includes(phrase))
})

return {
let CCPAdata = {
hasCCPALink: CCPALinks.length > 0,
CCPALinkPhrases: CCPALinks.map(link => link.textContent.trim().toLowerCase())
}
if (CCPAdata.hasCCPALink) {
CCPAdata.CCPALinkPhrases = CCPALinks.map(link => link.textContent.trim().toLowerCase())
}

return CCPAdata
})()

});
17 changes: 16 additions & 1 deletion tests/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,25 @@ ${metricsToLogString}
customMetrics.forEach(metricName => {
let wptCustomMetric = firstViewData[`_${metricName}`];
try {
// Some, but not all, custom metrics wrap their return values in JSON.stringify()
// Some just return the objects. And some have strings which are not JSON!
// Gotta love the consistency!!!
//
// IMHO wrapping the return in JSON.stringify() is best practice, since WebPageTest
// will do that to save to database and you can run into weird edge cases where it
// doesn't return data when doing that, so explicitly doing that avoids that when
// testing in the console* , but we live in an inconsistent world!
// (* see https://github.com/HTTPArchive/custom-metrics/pull/113#issuecomment-2043937823)
//
// Anyway, if it's a string, see if we can parse it back to a JS object to pretty
// print it, but be prepared for that to fail for non-JSON strings so wrap in try/catch
// See pipeline: https://github.com/HTTPArchive/data-pipeline/blob/main/modules/import_all.py#L115
if (typeof wptCustomMetric === 'string') {
wptCustomMetric = JSON.parse(wptCustomMetric);
}
} catch (e) { }
} catch (e) {
// If it fails, that's OK as we'll just stick with the exact string output anyway
}
wptCustomMetrics[`_${metricName}`] = wptCustomMetric;
});

Expand Down
Loading