Skip to content

Commit

Permalink
Platformio Adapter GDPR support (prebid#2787)
Browse files Browse the repository at this point in the history
* GDPR support
  • Loading branch information
varashellov authored and mike-chowla committed Jul 6, 2018
1 parent 772aa6f commit a2bb255
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/platformioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const spec = {
isBidRequestValid: bid => (
!!(bid && bid.params && bid.params.pubId && bid.params.placementId)
),
buildRequests: bidRequests => {
buildRequests: (bidRequests, bidderRequest) => {
const request = {
id: bidRequests[0].bidderRequestId,
at: 2,
Expand All @@ -32,6 +32,7 @@ export const spec = {
app: app(bidRequests),
device: device(bidRequests),
};
applyGdpr(bidderRequest, request);
return {
method: 'POST',
url: '//piohbdisp.hb.adx1.com/',
Expand Down Expand Up @@ -276,6 +277,13 @@ function parse(rawResponse) {
return null;
}

function applyGdpr(bidderRequest, ortbRequest) {
if (bidderRequest && bidderRequest.gdprConsent) {
ortbRequest.regs = { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0 } };
ortbRequest.user = { ext: { consent: bidderRequest.gdprConsent.consentString } };
}
}

function nativeResponse(imp, bid) {
if (imp['native']) {
const nativeAd = parse(bid.adm);
Expand Down
19 changes: 19 additions & 0 deletions test/spec/modules/platformioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,23 @@ describe('Platform.io Adapter Tests', () => {
expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps');
expect(ortbRequest.app.domain).to.equal('platform.io');
});

it('Verify GDPR', () => {
const bidderRequest = {
gdprConsent: {
gdprApplies: true,
consentString: 'serialized_gpdr_data'
}
};
const request = spec.buildRequests(slotConfigs, bidderRequest);
expect(request.url).to.equal('//piohbdisp.hb.adx1.com/');
expect(request.method).to.equal('POST');
const ortbRequest = JSON.parse(request.data);
expect(ortbRequest.user).to.not.equal(null);
expect(ortbRequest.user.ext).to.not.equal(null);
expect(ortbRequest.user.ext.consent).to.equal('serialized_gpdr_data');
expect(ortbRequest.regs).to.not.equal(null);
expect(ortbRequest.regs.ext).to.not.equal(null);
expect(ortbRequest.regs.ext.gdpr).to.equal(1);
});
});

0 comments on commit a2bb255

Please sign in to comment.