Skip to content

Commit

Permalink
emit request if consent not given
Browse files Browse the repository at this point in the history
  • Loading branch information
SleimanJneidi committed Mar 9, 2020
1 parent 55d147f commit 7efbcde
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 42 deletions.
104 changes: 63 additions & 41 deletions modules/quantcastBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import find from 'core-js/library/fn/array/find.js';

const BIDDER_CODE = 'quantcast';
const DEFAULT_BID_FLOOR = 0.0000000001;
const VENDOR_ID = 11;

export const QUANTCAST_DOMAIN = 'qcx.quantserve.com';
export const QUANTCAST_TEST_DOMAIN = 's2s-canary.quantserve.com';
Expand Down Expand Up @@ -73,6 +74,24 @@ function getDomain(url) {
return url.replace('http://', '').replace('https://', '').replace('www.', '').split(/[/?#]/)[0];
}

function hasConsent(gdprConsent, uspConsent) {
if (gdprConsent.gdprApplies) {
const vendorConsents = utils.deepAccess(gdprConsent, 'vendorData.vendorConsents');
if (vendorConsents) {
return vendorConsents.includes(VENDOR_ID);
} else {
return false;
}
}
if (uspConsent) {
return true;
}
if (Object.keys(gdprConsent).length == 0 && !uspConsent) {
return true;
}
return false;
}

/**
* The documentation for Prebid.js Adapter 1.0 can be found at link below,
* http://prebid.org/dev-docs/bidder-adapter-1.html
Expand Down Expand Up @@ -110,53 +129,56 @@ export const spec = {

let bidRequestsList = [];

bids.forEach(bid => {
let imp;
if (bid.mediaTypes) {
if (bid.mediaTypes.video && bid.mediaTypes.video.context === 'instream') {
imp = makeVideoImp(bid);
} else if (bid.mediaTypes.banner) {
imp = makeBannerImp(bid);
// dont send the request of consent is not given
if (hasConsent(gdprConsent, uspConsent)) {
bids.forEach(bid => {
let imp;
if (bid.mediaTypes) {
if (bid.mediaTypes.video && bid.mediaTypes.video.context === 'instream') {
imp = makeVideoImp(bid);
} else if (bid.mediaTypes.banner) {
imp = makeBannerImp(bid);
} else {
// Unsupported mediaType
utils.logInfo(`${BIDDER_CODE}: No supported mediaTypes found in ${JSON.stringify(bid.mediaTypes)}`);
return;
}
} else {
// Unsupported mediaType
utils.logInfo(`${BIDDER_CODE}: No supported mediaTypes found in ${JSON.stringify(bid.mediaTypes)}`);
return;
// Parse as banner by default
imp = makeBannerImp(bid);
}
} else {
// Parse as banner by default
imp = makeBannerImp(bid);
}

// Request Data Format can be found at https://wiki.corp.qc/display/adinf/QCX
const requestData = {
publisherId: bid.params.publisherId,
requestId: bid.bidId,
imp: [imp],
site: {
page,
referrer,
domain
},
bidId: bid.bidId,
gdprSignal: gdprConsent.gdprApplies ? 1 : 0,
gdprConsent: gdprConsent.consentString,
uspSignal: uspConsent ? 1 : 0,
uspConsent,
prebidJsVersion: '$prebid.version$'
};
// Request Data Format can be found at https://wiki.corp.qc/display/adinf/QCX
const requestData = {
publisherId: bid.params.publisherId,
requestId: bid.bidId,
imp: [imp],
site: {
page,
referrer,
domain
},
bidId: bid.bidId,
gdprSignal: gdprConsent.gdprApplies ? 1 : 0,
gdprConsent: gdprConsent.consentString,
uspSignal: uspConsent ? 1 : 0,
uspConsent,
prebidJsVersion: '$prebid.version$'
};

const data = JSON.stringify(requestData);
const qcDomain = bid.params.publisherId === QUANTCAST_TEST_PUBLISHER
? QUANTCAST_TEST_DOMAIN
: QUANTCAST_DOMAIN;
const url = `${QUANTCAST_PROTOCOL}://${qcDomain}:${QUANTCAST_PORT}/qchb`;
const data = JSON.stringify(requestData);
const qcDomain = bid.params.publisherId === QUANTCAST_TEST_PUBLISHER
? QUANTCAST_TEST_DOMAIN
: QUANTCAST_DOMAIN;
const url = `${QUANTCAST_PROTOCOL}://${qcDomain}:${QUANTCAST_PORT}/qchb`;

bidRequestsList.push({
data,
method: 'POST',
url
bidRequestsList.push({
data,
method: 'POST',
url
});
});
});
}

return bidRequestsList;
},
Expand Down
21 changes: 20 additions & 1 deletion test/spec/modules/quantcastBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,29 @@ describe('Quantcast adapter', function () {

expect(requests[0].data).to.equal(JSON.stringify(expectedBidRequest));
});

it('should send an empty bid request list if gdpr consent is not given', function () {
let bidderRequestCopy = JSON.parse(JSON.stringify(bidderRequest));
bidderRequestCopy.gdprConsent = {
gdprApplies: true,
vendorData: {
vendorConsents: [1, 10, 20]
}
};
const requests = qcSpec.buildRequests([bidRequest], bidderRequestCopy);
expect(requests.length).to.equal(0);
});

it('should create bid request list if uspConsent exist', function () {
let bidderRequestCopy = JSON.parse(JSON.stringify(bidderRequest));
bidderRequestCopy.uspConsent = {};
const requests = qcSpec.buildRequests([bidRequest], bidderRequestCopy);
expect(requests.length).to.equal(1);
});
});

it('propagates GDPR consent string and signal', function () {
const bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentString' } }
const bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentString', vendorData: {vendorConsents: [11]} } }
const requests = qcSpec.buildRequests([bidRequest], bidderRequest);
const parsed = JSON.parse(requests[0].data);
expect(parsed.gdprSignal).to.equal(1);
Expand Down

0 comments on commit 7efbcde

Please sign in to comment.