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

Add GDPR support to DAN Marketplace Bid Adapter #2605

Merged
merged 9 commits into from
May 25, 2018
24 changes: 21 additions & 3 deletions modules/danmarketBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const spec = {
return !!bid.params.uid;
},

buildRequests: function(validBidRequests) {
buildRequests: function(validBidRequests, bidderRequest) {
const auids = [];
const bidsMap = {};
const bids = validBidRequests || [];
Expand All @@ -57,6 +57,15 @@ export const spec = {
r: reqId,
};

if (bidderRequest && bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString) {
payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
}
payload.gdpr_applies =
(typeof bidderRequest.gdprConsent.gdprApplies === 'boolean')
? Number(bidderRequest.gdprConsent.gdprApplies) : 1;
}

return {
method: 'GET',
url: ENDPOINT_URL,
Expand Down Expand Up @@ -87,11 +96,20 @@ export const spec = {
return bidResponses;
},

getUserSyncs: function(syncOptions) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
if (syncOptions.pixelEnabled) {
var query = [];
if (gdprConsent) {
if (gdprConsent.consentString) {
query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString));
}
query.push('gdpr_applies=' + encodeURIComponent(
(typeof gdprConsent.gdprApplies === 'boolean')
? Number(gdprConsent.gdprApplies) : 1));
}
return [{
type: 'image',
url: ADAPTER_SYNC_URL
url: ADAPTER_SYNC_URL + (query.length ? '?' + query.join('&') : '')
}];
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/spec/modules/danmarketBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ describe('DAN_Marketplace Adapter', function () {
expect(payload).to.have.property('auids', '5,6');
delete bidRequests[1].params.priceType;
});

it('if gdprConsent is present payload must have gdpr params', () => {
const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}});
const payload = request.data;
expect(payload).to.be.an('object');
expect(payload).to.have.property('gdpr_consent', 'AAA');
expect(payload).to.have.property('gdpr_applies', 1);
});

it('if gdprApplies is false gdpr_applies must be 0', () => {
const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}});
const payload = request.data;
expect(payload).to.be.an('object');
expect(payload).to.have.property('gdpr_consent', 'AAA');
expect(payload).to.have.property('gdpr_applies', 0);
});

it('if gdprApplies is undefined gdpr_applies must be 1', () => {
const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}});
const payload = request.data;
expect(payload).to.be.an('object');
expect(payload).to.have.property('gdpr_consent', 'AAA');
expect(payload).to.have.property('gdpr_applies', 1);
});
});

describe('interpretResponse', () => {
Expand Down