Skip to content

Commit

Permalink
Add global privacy platform consent to amp-consent (#39789)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerivq committed Mar 7, 2024
1 parent 5ae1b19 commit 7e21644
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/amp-consent/diy-consent.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ <h1>Thank you!</h1>
additionalConsent: getAdditionalConsentString(),
gdprApplies: true,
purposeOne: true,
gppSectionId: undefined,
},
purposeConsents: {
"purpose-foo": true,
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-consent/0.1/amp-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ export class AmpConsent extends AMP.BaseElement {
opt_metadata['consentStringType'],
opt_metadata['additionalConsent'],
opt_metadata['gdprApplies'],
opt_metadata['purposeOne']
opt_metadata['purposeOne'],
opt_metadata['gppSectionId']
);
}

Expand Down
19 changes: 17 additions & 2 deletions extensions/amp-consent/0.1/consent-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const METADATA_STORAGE_KEY = {
ADDITIONAL_CONSENT: 'ac',
GDPR_APPLIES: 'ga',
PURPOSE_ONE: 'po',
GPP_SECTION_ID: 'gsi',
};

/**
Expand Down Expand Up @@ -95,6 +96,7 @@ export let ConsentInfoDef;
* additionalConsent: (string|undefined),
* gdprApplies: (boolean|undefined),
* purposeOne: (boolean|undefined),
* gppSectionId: (string|undefined),
* }}
*/
export let ConsentMetadataDef;
Expand Down Expand Up @@ -316,19 +318,22 @@ export function constructConsentInfo(
* @param {string=} opt_additionalConsent
* @param {boolean=} opt_gdprApplies
* @param {boolean=} opt_purposeOne
* @param {string=} opt_gppSectionId
* @return {!ConsentMetadataDef}
*/
export function constructMetadata(
opt_consentStringType,
opt_additionalConsent,
opt_gdprApplies,
opt_purposeOne
opt_purposeOne,
opt_gppSectionId
) {
return {
'consentStringType': opt_consentStringType,
'additionalConsent': opt_additionalConsent,
'gdprApplies': opt_gdprApplies,
'purposeOne': opt_purposeOne,
'gppSectionId': opt_gppSectionId,
};
}

Expand Down Expand Up @@ -420,6 +425,10 @@ export function composeMetadataStoreValue(consentInfoMetadata) {
storageMetadata[METADATA_STORAGE_KEY.PURPOSE_ONE] =
consentInfoMetadata['purposeOne'];
}
if (consentInfoMetadata['gppSectionId'] != undefined) {
storageMetadata[METADATA_STORAGE_KEY.GPP_SECTION_ID] =
consentInfoMetadata['gppSectionId'];
}
return storageMetadata;
}

Expand All @@ -439,7 +448,8 @@ export function convertStorageMetadata(storageMetadata) {
storageMetadata[METADATA_STORAGE_KEY.CONSENT_STRING_TYPE],
storageMetadata[METADATA_STORAGE_KEY.ADDITIONAL_CONSENT],
storageMetadata[METADATA_STORAGE_KEY.GDPR_APPLIES],
storageMetadata[METADATA_STORAGE_KEY.PURPOSE_ONE]
storageMetadata[METADATA_STORAGE_KEY.PURPOSE_ONE],
storageMetadata[METADATA_STORAGE_KEY.GPP_SECTION_ID]
);
}

Expand All @@ -453,6 +463,7 @@ export function assertMetadataValues(metadata) {
const additionalConsent = metadata['additionalConsent'];
const gdprApplies = metadata['gdprApplies'];
const purposeOne = metadata['purposeOne'];
const gppSectionId = metadata['gppSectionId'];
const errorFields = [];

if (
Expand All @@ -474,6 +485,10 @@ export function assertMetadataValues(metadata) {
delete metadata['purposeOne'];
errorFields.push('purposeOne');
}
if (gppSectionId && typeof gppSectionId != 'string') {
delete metadata['gppSectionId'];
errorFields.push('gppSectionId');
}
for (let i = 0; i < errorFields.length; i++) {
user().error(
TAG,
Expand Down
13 changes: 12 additions & 1 deletion extensions/amp-consent/0.1/test/test-consent-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': undefined,
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(
convertStorageMetadata({
Expand All @@ -173,6 +174,7 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': undefined,
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(
convertStorageMetadata({
Expand All @@ -184,19 +186,22 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': '1~1.35.41.101',
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(
convertStorageMetadata({
[METADATA_STORAGE_KEY.CONSENT_STRING_TYPE]:
CONSENT_STRING_TYPE.US_PRIVACY_STRING,
[METADATA_STORAGE_KEY.ADDITIONAL_CONSENT]: '1~1.35.41.101',
[METADATA_STORAGE_KEY.PURPOSE_ONE]: true,
[METADATA_STORAGE_KEY.GPP_SECTION_ID]: '8',
})
).to.deep.equal({
'consentStringType': CONSENT_STRING_TYPE.US_PRIVACY_STRING,
'additionalConsent': '1~1.35.41.101',
'gdprApplies': undefined,
'purposeOne': true,
'gppSectionId': '8',
});
});

Expand Down Expand Up @@ -456,6 +461,7 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': undefined,
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(
constructMetadata(CONSENT_STRING_TYPE.US_PRIVACY_STRING)
Expand All @@ -464,12 +470,14 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': undefined,
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(constructMetadata(undefined, '1~1.35.41.101')).to.deep.equal({
'consentStringType': undefined,
'additionalConsent': '1~1.35.41.101',
'gdprApplies': undefined,
'purposeOne': undefined,
'gppSectionId': undefined,
});
expect(
constructMetadata(undefined, undefined, true, false)
Expand All @@ -478,19 +486,22 @@ describes.fakeWin('ConsentInfo', {}, () => {
'additionalConsent': undefined,
'gdprApplies': true,
'purposeOne': false,
'gppSectionId': undefined,
});
expect(
constructMetadata(
CONSENT_STRING_TYPE.US_PRIVACY_STRING,
'1~1.35.41.101',
true,
true
true,
undefined
)
).to.deep.equal({
'consentStringType': CONSENT_STRING_TYPE.US_PRIVACY_STRING,
'additionalConsent': '1~1.35.41.101',
'gdprApplies': true,
'purposeOne': true,
'gppSectionId': undefined,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ Similar to the consent string, AMP will always pass the local stored consent met

```
{
"consentStringType": {enum} [CONSENT_STRING_TYPE.TCF_V1, CONSENT_STRING_TYPE.TCF_V2, CONSENT_STRING_TYPE.US_PRIVACY_STRING] (optional),
"consentStringType": {enum} [CONSENT_STRING_TYPE.TCF_V1, CONSENT_STRING_TYPE.TCF_V2, CONSENT_STRING_TYPE.US_PRIVACY_STRING, GLOBAL_PRIVACY_PLATFORM] (optional),
"gdprApplies": {boolean} (optional),
"additionalConsent": {string} (optional),
"purposeOne": {boolean} (optional)
"purposeOne": {boolean} (optional),
"gppSectionId": {string} (optional),
}
```
3 changes: 2 additions & 1 deletion extensions/amp-consent/integrating-consent.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ info = JSON.parse(window.name);
"consentStringType": {enum} [1: TCF V1, 2: TCF V2, 3: US Privacy String] (optional),
"gdprApplies": {boolean} (optional),
"additionalConsent": {string} (optional),
"purposeOne": {boolean} (optional)
"purposeOne": {boolean} (optional),
"gppSectionId": {string} (optional)
}
```

Expand Down

0 comments on commit 7e21644

Please sign in to comment.