Skip to content

Commit

Permalink
rtbhouse adapter GDPR integration. (prebid#2641)
Browse files Browse the repository at this point in the history
* Add files via upload

* Delete rtbhouseBidAdapter_spec.js

* Delete rtbhouseBidAdapter.js

* Added GDPR integration to RTBhouse adapter

* Update rtbhouseBidAdapter_spec.js

* Added GDPR consent as second build attribute.

* Added gdpr as second attribute in test.
  • Loading branch information
Marcian123 authored and Pupis committed Jun 7, 2018
1 parent 5dda13b commit 9894dab
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
11 changes: 9 additions & 2 deletions modules/rtbhouseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,22 @@ export const spec = {
isBidRequestValid: function (bid) {
return !!(includes(REGIONS, bid.params.region) && bid.params.publisherId);
},

buildRequests: function (validBidRequests) {
buildRequests: function (validBidRequests, bidderRequest) {
const request = {
id: validBidRequests[0].auctionId,
imp: validBidRequests.map(slot => mapImpression(slot)),
site: mapSite(validBidRequests),
cur: DEFAULT_CURRENCY_ARR,
test: validBidRequests[0].params.test || 0
};
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
const consentStr = (bidderRequest.gdprConsent.consentString)
? bidderRequest.gdprConsent.consentString.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '') : '';
const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
request.regs = {ext: {gdpr: gdpr}};
request.user = {ext: {consent: consentStr}};
};

return {
method: 'POST',
url: buildEndpointUrl(validBidRequests[0].params.region),
Expand Down
32 changes: 29 additions & 3 deletions test/spec/modules/rtbhouseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory';

const REGIONS = ['prebid-eu', 'prebid-us', 'prebid-asia'];
const ENDPOINT_URL = 'creativecdn.com/bidder/prebid/bids';

const consentStr = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
/**
* Helpers
*/
Expand Down Expand Up @@ -79,12 +79,38 @@ describe('RTBHouseAdapter', () => {
it('sends bid request to ENDPOINT via POST', () => {
let bidRequest = Object.assign([], bidRequests);
delete bidRequest[0].params.test;

const request = spec.buildRequests(bidRequest);
expect(request.url).to.equal(buildEndpointUrl(bidRequest[0].params.region));
expect(request.method).to.equal('POST');
});
})

it('should not populate GDPR if for non-EEA users', () => {
let bidRequest = Object.assign([], bidRequests);
delete bidRequest[0].params.test;
const request = spec.buildRequests(bidRequest);
let data = JSON.parse(request.data);
expect(data).to.not.have.property('regs');
expect(data).to.not.have.property('user');
});

it('should populate GDPR and consent string if available for EEA users', () => {
let bidRequest = Object.assign([], bidRequests);
delete bidRequest[0].params.test;
const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: consentStr}});
let data = JSON.parse(request.data);
expect(data.regs.ext.gdpr).to.equal(1);
expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A');
});

it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', () => {
let bidRequest = Object.assign([], bidRequests);
delete bidRequest[0].params.test;
const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true}});
let data = JSON.parse(request.data);
expect(data.regs.ext.gdpr).to.equal(1);
expect(data.user.ext.consent).to.equal('');
});
});

describe('interpretResponse', () => {
let response = [{
Expand Down

0 comments on commit 9894dab

Please sign in to comment.