Skip to content

Commit

Permalink
add gpp suport (#11381)
Browse files Browse the repository at this point in the history
Co-authored-by: Dawid W <[email protected]>
  • Loading branch information
optidigital-prebid and dawidww committed Apr 23, 2024
1 parent 61f4052 commit 91aa96e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
24 changes: 20 additions & 4 deletions modules/optidigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,24 @@ export const spec = {
}
}

if (bidderRequest?.gppConsent?.gppString) {
payload.gpp = {
consent: bidderRequest.gppConsent.gppString,
sid: bidderRequest.gppConsent.applicableSections
}
} else if (bidderRequest?.ortb2?.regs?.gpp) {
payload.gpp = {
consent: bidderRequest.ortb2.regs.gpp,
sid: bidderRequest.ortb2.regs.gpp_sid
}
}

if (window.location.href.indexOf('optidigitalTestMode=true') !== -1) {
payload.testMode = true;
}

if (bidderRequest && bidderRequest.uspConsent) {
payload.uspConsent = bidderRequest.uspConsent;
payload.us_privacy = bidderRequest.uspConsent;
}

if (_getEids(validBidRequests[0])) {
Expand Down Expand Up @@ -153,16 +165,20 @@ export const spec = {
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
let syncurl = '';
if (!isSynced) {
// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent && uspConsent.consentString) {
syncurl += `&ccpa_consent=${uspConsent.consentString}`;
if (uspConsent) {
syncurl += '&us_privacy=' + encodeURIComponent(uspConsent);
}
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
syncurl += '&gpp=' + encodeURIComponent(gppConsent.gppString);
syncurl += '&gpp_sid=' + encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

if (syncOptions.iframeEnabled) {
Expand Down
38 changes: 34 additions & 4 deletions test/spec/modules/optidigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,32 @@ describe('optidigitalAdapterTests', function () {
bidderRequest.uspConsent = '1YYY';
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.uspConsent).to.exist;
expect(payload.us_privacy).to.exist;
});

it('should send gppConsent to given endpoint where there is gppConsent', function() {
let consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==';
bidderRequest.gppConsent = {
'gppString': consentString,
'applicableSections': [7]
};
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.gpp).to.exist;
});

it('should send gppConsent to given endpoint when there is gpp in ortb2', function() {
let consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==';
bidderRequest.gppConsent = undefined;
bidderRequest.ortb2 = {
regs: {
gpp: consentString,
gpp_sid: [7]
}
}
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.gpp).to.exist;
});

it('should use appropriate mediaTypes banner sizes', function() {
Expand Down Expand Up @@ -546,9 +571,14 @@ describe('optidigitalAdapterTests', function () {
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=`
}]);
});
it('should return appropriate URL with GDPR equals to 1, GDPR consent and CCPA consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, {consentString: 'fooUsp'})).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&ccpa_consent=fooUsp`
it('should return appropriate URL with GDPR equals to 1, GDPR consent and US Privacy consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp')).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp`
}]);
});
it('should return appropriate URL with GDPR equals to 1, GDPR consent, US Privacy consent and GPP consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp', {gppString: 'fooGpp', applicableSections: [7]})).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp&gpp=fooGpp&gpp_sid=7`
}]);
});
});
Expand Down

0 comments on commit 91aa96e

Please sign in to comment.