Skip to content

support gdpr for one video adapter #2981

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

Merged
merged 2 commits into from
Aug 23, 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
30 changes: 27 additions & 3 deletions modules/oneVideoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ export const spec = {
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @param bidderRequest
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(bids) {
buildRequests: function(bids, bidRequest) {
let consentData = bidRequest ? bidRequest.gdprConsent : null;

return bids.map(bid => {
return {
method: 'POST',
url: location.protocol + spec.ENDPOINT + bid.params.pubId,
data: getRequestData(bid),
data: getRequestData(bid, consentData),
options: {contentType: 'application/json'},
bidRequest: bid
}
Expand Down Expand Up @@ -127,7 +130,11 @@ function getSize(sizes) {
};
}

function getRequestData(bid) {
function isConsentRequired(consentData) {
return !!(consentData && consentData.gdprApplies);
}

function getRequestData(bid, consentData) {
let loc = utils.getTopWindowLocation();
let global = (window.top) ? window.top : window;
let page = (bid.params.site && bid.params.site.page) ? (bid.params.site.page) : (loc.href);
Expand Down Expand Up @@ -179,6 +186,23 @@ function getRequestData(bid) {
if (bid.params.site && bid.params.site.id) {
bidData.site.id = bid.params.site.id
}

if (isConsentRequired(consentData)) {
bidData.regs = {
ext: {
gdpr: 1
}
};

if (consentData.consentString) {
bidData.user = {
ext: {
consent: consentData.consentString
}
};
}
}

return bidData;
}

Expand Down
32 changes: 32 additions & 0 deletions test/spec/modules/oneVideoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { expect } from 'chai';
import { spec } from 'modules/oneVideoBidAdapter';
import * as utils from 'src/utils';
import {config} from 'src/config';

describe('OneVideoBidAdapter', () => {
let bidRequest;
let bidderRequest;
let mockConfig;

beforeEach(() => {
bidRequest = {
Expand Down Expand Up @@ -132,4 +135,33 @@ describe('OneVideoBidAdapter', () => {
expect(bidResponse).to.deep.equal(o);
});
});

describe('when GDPR applies', function () {
beforeEach(function () {
bidderRequest = {
gdprConsent: {
consentString: 'test-gdpr-consent-string',
gdprApplies: true
}
};

mockConfig = {
consentManagement: {
cmpApi: 'iab',
timeout: 1111,
allowAuctionWithoutConsent: 'cancel'
}
};
});

it('should send a signal to specify that GDPR applies to this request', function () {
const request = spec.buildRequests([ bidRequest ], bidderRequest);
expect(request[0].data.regs.ext.gdpr).to.equal(1);
});

it('should send the consent string', function () {
const request = spec.buildRequests([ bidRequest ], bidderRequest);
expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString);
});
});
});