Skip to content

Commit

Permalink
Privacy - IAB Global Privacy Platform (#138)
Browse files Browse the repository at this point in the history
* iab_gpp

* restore comment

* no empty data

* to trigger the test

* skip logging details
  • Loading branch information
max-ostapenko authored Jul 25, 2024
1 parent 6cb50e0 commit 0009e13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
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

0 comments on commit 0009e13

Please sign in to comment.