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

rtbhouse adapter GDPR integration. #2641

Merged
merged 7 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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