Skip to content

Commit

Permalink
✨ Add support for passing GPP fields for amp-ad-network-doubleclick a…
Browse files Browse the repository at this point in the history
…nd adsense (#39874)

* Add support for passing GPP fields for amp-ad-network-doubleclick and adsense.

* Fix amp-a4a tests
  • Loading branch information
zombifier committed Mar 12, 2024
1 parent 92b0202 commit a5f56b5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
5 changes: 5 additions & 0 deletions extensions/amp-a4a/0.1/amp-a4a.js
Expand Up @@ -145,6 +145,7 @@ export let CreativeMetaDataDef;
gdprApplies: (?boolean|undefined),
additionalConsent: (?string|undefined),
consentSharedData: (?Object|undefined),
gppSectionId: (?string|undefined),
}} */
export let ConsentTupleDef;

Expand Down Expand Up @@ -787,6 +788,9 @@ export class AmpA4A extends AMP.BaseElement {
const consentStringType = consentMetadata
? consentMetadata['consentStringType']
: consentMetadata;
const gppSectionId = consentMetadata
? consentMetadata['gppSectionId']
: consentMetadata;

return /** @type {!Promise<?string>} */ (
this.getServeNpaSignal().then((npaSignal) =>
Expand All @@ -798,6 +802,7 @@ export class AmpA4A extends AMP.BaseElement {
gdprApplies,
additionalConsent,
consentSharedData,
gppSectionId,
},
this.tryExecuteRealTimeConfig_(
consentState,
Expand Down
4 changes: 4 additions & 0 deletions extensions/amp-a4a/0.1/test/test-amp-a4a.js
Expand Up @@ -2811,6 +2811,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
gdprApplies,
'consentStringType': 1,
'additionalConsent': 'abc123',
'gppSectionId': '1,2',
};
consentSharedData = {
'doubleclick-tfcd': 1,
Expand Down Expand Up @@ -2857,6 +2858,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
consentStringType: consentMetadata['consentStringType'],
additionalConsent: consentMetadata['additionalConsent'],
consentSharedData,
gppSectionId: consentMetadata['gppSectionId'],
})
).calledOnce;
expect(
Expand Down Expand Up @@ -2913,6 +2915,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
consentStringType: consentMetadata['consentStringType'],
additionalConsent: consentMetadata['additionalConsent'],
consentSharedData,
gppSectionId: consentMetadata['gppSectionId'],
})
).calledOnce;
expect(
Expand Down Expand Up @@ -2963,6 +2966,7 @@ describes.realWin('amp-a4a', {amp: true}, (env) => {
gdprApplies: null,
additionalConsent: null,
consentSharedData: null,
gppSectionId: null,
})
).calledOnce;
expect(
Expand Down
Expand Up @@ -279,13 +279,15 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
let additionalConsent = undefined;
let consentStringType = undefined;
let consentSharedData = undefined;
let gppSectionId = undefined;
if (consentTuple) {
consentState = consentTuple.consentState;
consentString = consentTuple.consentString;
gdprApplies = consentTuple.gdprApplies;
additionalConsent = consentTuple.additionalConsent;
consentStringType = consentTuple.consentStringType;
consentSharedData = consentTuple.consentSharedData;
gppSectionId = consentTuple.gppSectionId;
}
if (
consentState == CONSENT_POLICY_STATE.UNKNOWN &&
Expand Down Expand Up @@ -380,10 +382,13 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
? this.responsiveState_.getRafmtParam()
: null,
'gdpr': gdprApplies === true ? '1' : gdprApplies === false ? '0' : null,
'gdpr_consent':
consentStringType != CONSENT_STRING_TYPE.US_PRIVACY_STRING
? consentString
: null,
'gdpr_consent': [
undefined,
CONSENT_STRING_TYPE.TCF_V1,
CONSENT_STRING_TYPE.TCF_V2,
].includes(consentStringType)
? consentString
: null,
'addtl_consent': additionalConsent,
'us_privacy':
consentStringType == CONSENT_STRING_TYPE.US_PRIVACY_STRING
Expand All @@ -405,6 +410,14 @@ export class AmpAdNetworkAdsenseImpl extends AmpA4A {
: null,
'tfcd': consentSharedData?.['adsense-tfcd'] ?? null,
'tfua': consentSharedData?.['adsense-tfua'] ?? null,
'gpp':
consentStringType == CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM
? consentString
: null,
'gpp_sid':
consentStringType == CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM
? gppSectionId
: null,
};

const experimentIds = [];
Expand Down
Expand Up @@ -962,6 +962,21 @@ describes.realWin(
});
});

it('should include gpp, if consentStringType is GLOBAL_PRIVACY_PLATFORM', () => {
impl.uiHandler = {isStickyAd: () => false};
return impl
.getAdUrl({
consentStringType: CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM,
consentString: 'gppString',
gppSectionId: '1,2',
})
.then((url) => {
expect(url).to.match(/(\?|&)gpp=gppString(&|$)/);
expect(url).to.match(/(\?|&)gpp_sid=1%2C2(&|$)/);
expect(url).to.not.match(/(\?|&)us_privacy=/);
});
});

describe('SSR experiments', () => {
it('should include SSR experiments', () => {
env.sandbox
Expand Down
Expand Up @@ -621,6 +621,7 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
consentString,
consentStringType,
gdprApplies,
gppSectionId,
} = consentTuple;

const tfcdFromSharedData = consentSharedData?.['doubleclick-tfcd'];
Expand All @@ -642,17 +643,28 @@ export class AmpAdNetworkDoubleclickImpl extends AmpA4A {
'gct': this.getLocationQueryParameterValue('google_preview') || null,
'psts': tokens.length ? tokens : null,
'gdpr': gdprApplies === true ? '1' : gdprApplies === false ? '0' : null,
'gdpr_consent':
consentStringType != CONSENT_STRING_TYPE.US_PRIVACY_STRING
? consentString
: null,
'gdpr_consent': [
undefined,
CONSENT_STRING_TYPE.TCF_V1,
CONSENT_STRING_TYPE.TCF_V2,
].includes(consentStringType)
? consentString
: null,
'addtl_consent': additionalConsent,
'us_privacy':
consentStringType == CONSENT_STRING_TYPE.US_PRIVACY_STRING
? consentString
: null,
'tfcd': combineConsentParams(tfcdFromSharedData, tfcdFromJson),
'tfua': combineConsentParams(tfuaFromSharedData, tfuaFromJson),
'gpp':
consentStringType == CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM
? consentString
: null,
'gpp_sid':
consentStringType == CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM
? gppSectionId
: null,
};
}

Expand Down
Expand Up @@ -1259,6 +1259,21 @@ for (const {config, name} of [
expect(url).to.match(/(\?|&)tfcd=1(&|$)/);
});
});

it('should include gpp, if consentStringType is GLOBAL_PRIVACY_PLATFORM', () => {
impl.uiHandler = {isStickyAd: () => false};
return impl
.getAdUrl({
consentStringType: CONSENT_STRING_TYPE.GLOBAL_PRIVACY_PLATFORM,
consentString: 'gppString',
gppSectionId: '1,2',
})
.then((url) => {
expect(url).to.match(/(\?|&)gpp=gppString(&|$)/);
expect(url).to.match(/(\?|&)gpp_sid=1%2C2(&|$)/);
expect(url).to.not.match(/(\?|&)us_privacy=/);
});
});
});

describe('#getPageParameters', () => {
Expand Down

0 comments on commit a5f56b5

Please sign in to comment.