Skip to content

Commit

Permalink
Merge pull request #11 from playground-xyz/3750-add-gdpr-consent-supp…
Browse files Browse the repository at this point in the history
…ort-the-pxyz-prebidjs-adapter

GDPR integration
  • Loading branch information
teranchristian authored Jun 7, 2018
2 parents 3552ab2 + 0476a76 commit 79e5355
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 45 deletions.
12 changes: 9 additions & 3 deletions modules/playgroundxyzBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const spec = {
*/
buildRequests: function (bidRequests, bidderRequest) {
const topLocation = utils.getTopWindowLocation();
const payload = JSON.stringify({
const payload = {
id: bidRequests[0].auctionId,
site: {
domain: window.location.protocol + '//' + topLocation.hostname,
Expand All @@ -41,17 +41,23 @@ export const spec = {
devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2,
},
imp: bidRequests.map(mapImpression)
});
};

const options = {
contentType: 'application/json',
withCredentials: false
};

if (bidderRequest && bidderRequest.gdprConsent) {
payload.user = {ext: {consent: bidderRequest.gdprConsent.consentString}};
const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
payload.regs = {ext: {gdpr: gdpr}};
}

return {
method: 'POST',
url: URL,
data: payload,
data: JSON.stringify(payload),
options,
bidderRequest
};
Expand Down
42 changes: 0 additions & 42 deletions modules/playgroundxyzBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,6 @@ var adUnits = [
placementId: '10433394'
}
}]
},
// Video instream adUnit
{
code: 'video-instream',
sizes: [640, 480],
mediaTypes: {
video: {
context: 'instream'
},
},
bids: [{
bidder: 'playgroundxyz',
params: {
placementId: '9333431',
video: {
skippable: true,
playback_methods: ['auto_play_sound_off']
}
}
}]
},
// Video outstream adUnit
{
code: 'video-outstream',
sizes: [[640, 480]],
mediaTypes: {
video: {
context: 'outstream'
}
},
bids: [
{
bidder: 'playgroundxyz',
params: {
placementId: '5768085',
video: {
skippable: true,
playback_method: ['auto_play_sound_off']
}
}
}
]
}
];
```
49 changes: 49 additions & 0 deletions test/spec/modules/playgroundxyzBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory';
import { deepClone } from 'src/utils';

const URL = 'https://ads.playground.xyz/host-config/prebid';
const GDPR_CONSENT = 'XYZ-CONSENT';

describe('playgroundxyzBidAdapter', () => {
const adapter = newBidder(spec);
Expand Down Expand Up @@ -133,4 +134,52 @@ describe('playgroundxyzBidAdapter', () => {
expect(result.length).to.equal(0);
});
});

describe('buildRequests', () => {
let bidRequests = [
{
'bidder': 'playgroundxyz',
'params': {
'publisherId': 'PUB_FAKE'
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'bidId': '321db112312as',
'bidderRequestId': '23edabce2731sd6',
'auctionId': '12as040790a475'
}
];

it('should not populate GDPR', () => {
let bidRequest = Object.assign([], bidRequests);
const request = spec.buildRequests(bidRequest);
let data = JSON.parse(request.data);
expect(data).to.not.have.property('user');
expect(data).to.not.have.property('regs');
});

it('should populate GDPR and consent string when consetString is presented but not gdpApplies', () => {
let bidRequest = Object.assign([], bidRequests);
const request = spec.buildRequests(bidRequest, {gdprConsent: {consentString: GDPR_CONSENT}});
let data = JSON.parse(request.data);
expect(data.regs.ext.gdpr).to.equal(0);
expect(data.user.ext.consent).to.equal('XYZ-CONSENT');
});

it('should populate GDPR and consent string when gdpr is set to true', () => {
let bidRequest = Object.assign([], bidRequests);
const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: GDPR_CONSENT}});
let data = JSON.parse(request.data);
expect(data.regs.ext.gdpr).to.equal(1);
expect(data.user.ext.consent).to.equal('XYZ-CONSENT');
});

it('should populate GDPR and consent string when gdpr is set to false', () => {
let bidRequest = Object.assign([], bidRequests);
const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: false, consentString: GDPR_CONSENT}});
let data = JSON.parse(request.data);
expect(data.regs.ext.gdpr).to.equal(0);
expect(data.user.ext.consent).to.equal('XYZ-CONSENT');
});
});
});

0 comments on commit 79e5355

Please sign in to comment.