Skip to content

Commit

Permalink
Consumable Bid Adapter: Pass GDPR and Prebid version info. Pixel sync…
Browse files Browse the repository at this point in the history
…s. (prebid#3578)
  • Loading branch information
jgrimes authored and mkendall07 committed Mar 15, 2019
1 parent b4870e7 commit 9e0f00c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
33 changes: 18 additions & 15 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/

buildRequests: function(validBidRequests) {
// Do we need to group by bidder? i.e. to make multiple requests for
// different endpoints.

buildRequests: function(validBidRequests, bidderRequest) {
let ret = {
method: 'POST',
url: '',
Expand All @@ -50,14 +47,21 @@ export const spec = {
const data = Object.assign({
placements: [],
time: Date.now(),
user: {},
url: utils.getTopWindowUrl(),
referrer: document.referrer,
enableBotFiltering: true,
includePricingData: true,
parallel: true
source: [{
'name': 'prebidjs',
'version': '$prebid.version$'
}]
}, validBidRequests[0].params);

if (bidderRequest && bidderRequest.gdprConsent) {
data.gdpr = {
consent: bidderRequest.gdprConsent.consentString,
applies: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
};
}

validBidRequests.map(bid => {
const placement = Object.assign({
divName: bid.bidId,
Expand Down Expand Up @@ -123,12 +127,16 @@ export const spec = {
return bidResponses;
},

getUserSyncs: function(syncOptions) {
getUserSyncs: function(syncOptions, serverResponses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: '//sync.serverbid.com/ss/' + siteId + '.html'
}];
}

if (syncOptions.pixelEnabled && serverResponses.length > 0) {
return serverResponses[0].body.pixels;
} else {
utils.logWarn(bidder + ': Please enable iframe based user syncing.');
}
Expand Down Expand Up @@ -192,12 +200,7 @@ function getSize(sizes) {
}

function retrieveAd(decision, unitId, unitName) {
let oad = decision.contents && decision.contents[0] && decision.contents[0].body + utils.createTrackPixelHtml(decision.impressionUrl);
let cb = Math.round(new Date().getTime());
let ad = '<script type=\'text/javascript\'>document.write(\'<div id=\"' + unitName + '-' + unitId + '\">\');</script>' + oad;
ad += '<script type=\'text/javascript\'>document.write(\'</div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<div class=\"' + unitName + '\"></div>\');</script>';
ad += '<script type=\'text/javascript\'>document.write(\'<scr\'+\'ipt type=\"text/javascript\" src=\"https://yummy.consumable.com/' + unitId + '/' + unitName + '/widget/unit.js?cb=' + cb + '\" charset=\"utf-8\" async></scr\'+\'ipt>\');</script>'
let ad = decision.contents && decision.contents[0] && decision.contents[0].body + utils.createTrackPixelHtml(decision.impressionUrl);

return ad;
}
Expand Down
14 changes: 13 additions & 1 deletion test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const REQUEST = {
'bidderRequestId': '109f2a181342a9',
'auctionId': 'a4713c32-3762-4798-b342-4ab810ca770d'
}],
'gdprConsent': {
'consentString': 'consent-test',
'gdprApplies': true
},
'start': 1487883186070,
'auctionStart': 1487883186069,
'timeout': 3000
Expand All @@ -52,6 +56,7 @@ const RESPONSE = {
'headers': null,
'body': {
'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' },
'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }],
'decisions': {
'2b0f82502298c9': {
'adId': 2364764,
Expand Down Expand Up @@ -206,7 +211,7 @@ describe('Consumable BidAdapter', function () {
});
describe('interpretResponse validation', function () {
it('response should have valid bidderCode', function () {
let bidRequest = spec.buildRequests(REQUEST.bidRequest);
let bidRequest = spec.buildRequests(REQUEST.bidRequest, REQUEST);
let bid = createBid(1, bidRequest.bidRequest[0]);

expect(bid.bidderCode).to.equal('consumable');
Expand Down Expand Up @@ -264,5 +269,12 @@ describe('Consumable BidAdapter', function () {

expect(opts.length).to.equal(1);
});

it('should return a sync url if pixel syncs are enabled and some are returned from the server', function () {
let syncOptions = {'pixelEnabled': true};
let opts = spec.getUserSyncs(syncOptions, [RESPONSE]);

expect(opts.length).to.equal(1);
});
});
});

0 comments on commit 9e0f00c

Please sign in to comment.