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

consumable Bid Adapter : add bidResponse fields #8252

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
34 changes: 28 additions & 6 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,30 @@ export const spec = {
bid.currency = 'USD';
bid.creativeId = decision.adId;
bid.ttl = 30;
bid.meta = { advertiserDomains: decision.adomain ? decision.adomain : [] }
bid.netRevenue = true;
bid.referrer = bidRequest.bidderRequest.refererInfo.referer;

bid.meta = {
advertiserDomains: decision.adomain || []
};

if (decision.cats) {
if (decision.cats.length > 0) {
bid.meta.primaryCatId = decision.cats[0];
if (decision.cats.length > 1) {
bid.meta.secondaryCatIds = decision.cats.slice(1);
}
}
}

if (decision.networkId) {
bid.meta.networkId = decision.networkId;
}

if (decision.mediaType) {
bid.meta.mediaType = decision.mediaType;
}

bidResponses.push(bid);
}
}
Expand All @@ -136,13 +156,15 @@ export const spec = {

getUserSyncs: function(syncOptions, serverResponses) {
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://sync.serverbid.com/ss/' + siteId + '.html'
}];
if (!serverResponses || serverResponses.length === 0 || !serverResponses[0].body.bdr || serverResponses[0].body.bdr !== 'cx') {
return [{
type: 'iframe',
url: 'https://sync.serverbid.com/ss/' + siteId + '.html'
}];
}
}

if (syncOptions.pixelEnabled && serverResponses.length > 0) {
if (syncOptions.pixelEnabled && serverResponses && serverResponses.length > 0) {
return serverResponses[0].body.pixels;
} else {
logWarn(bidder + ': Please enable iframe based user syncing.');
Expand Down
89 changes: 87 additions & 2 deletions test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,69 @@ const AD_SERVER_RESPONSE = {
}
};

const AD_SERVER_RESPONSE_2 = {
'headers': null,
'body': {
'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' },
'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }],
'bdr': 'notcx',
'decisions': {
'2b0f82502298c9': {
'adId': 2364764,
'creativeId': 1950991,
'flightId': 2788300,
'campaignId': 542982,
'clickUrl': 'https://e.serverbid.com/r',
'impressionUrl': 'https://e.serverbid.com/i.gif',
'contents': [{
'type': 'html',
'body': '<html></html>',
'data': {
'height': 90,
'width': 728,
'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif',
'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif'
},
'template': 'image'
}],
'height': 90,
'width': 728,
'events': [],
'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5},
'mediaType': 'banner',
'cats': ['IAB1', 'IAB2', 'IAB3'],
'networkId': 1234567,
},
'123': {
'adId': 2364764,
'creativeId': 1950991,
'flightId': 2788300,
'campaignId': 542982,
'clickUrl': 'https://e.serverbid.com/r',
'impressionUrl': 'https://e.serverbid.com/i.gif',
'contents': [{
'type': 'html',
'body': '<html></html>',
'data': {
'height': 90,
'width': 728,
'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif',
'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif'
},
'template': 'image'
}],
'height': 90,
'width': 728,
'events': [],
'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5},
'mediaType': 'banner',
'cats': ['IAB1', 'IAB2'],
'networkId': 2345678,
}
}
}
};

const BUILD_REQUESTS_OUTPUT = {
method: 'POST',
url: 'https://e.serverbid.com/api/v2',
Expand Down Expand Up @@ -285,7 +348,7 @@ describe('Consumable BidAdapter', function () {
});

it('registers bids', function () {
let bids = spec.interpretResponse(AD_SERVER_RESPONSE, BUILD_REQUESTS_OUTPUT);
let bids = spec.interpretResponse(AD_SERVER_RESPONSE_2, BUILD_REQUESTS_OUTPUT);
bids.forEach(b => {
expect(b).to.have.property('cpm');
expect(b.cpm).to.be.above(0);
Expand All @@ -299,9 +362,13 @@ describe('Consumable BidAdapter', function () {
expect(b).to.have.property('currency', 'USD');
expect(b).to.have.property('creativeId');
expect(b).to.have.property('ttl', 30);
expect(b.meta).to.have.property('advertiserDomains');
expect(b).to.have.property('netRevenue', true);
expect(b).to.have.property('referrer');
expect(b.meta).to.have.property('advertiserDomains');
expect(b.meta).to.have.property('primaryCatId');
expect(b.meta).to.have.property('secondaryCatIds');
expect(b.meta).to.have.property('networkId');
expect(b.meta).to.have.property('mediaType');
});
});

Expand Down Expand Up @@ -333,6 +400,24 @@ describe('Consumable BidAdapter', function () {
expect(opts.length).to.equal(1);
});

it('should return a sync url if iframe syncs are enabled and server response is empty', function () {
let opts = spec.getUserSyncs(syncOptions, []);

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

it('should return a sync url if iframe syncs are enabled and server response does not contain a bdr attribute', function () {
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE]);

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

it('should return a sync url if iframe syncs are enabled and server response contains a bdr attribute that is not cx', function () {
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE_2]);

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, [AD_SERVER_RESPONSE]);
Expand Down