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

Smart Ad Server: add advertiser domain support and read more mediaTypes.video params #6944

Merged
Merged
28 changes: 25 additions & 3 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,36 @@ export const spec = {
h: size[1]
}));
} else if (videoMediaType && (videoMediaType.context === 'instream' || videoMediaType.context === 'outstream')) {
// use IAB ORTB values if the corresponding values weren't already set by bid.params.video
// Assign a default protocol, the highest value possible means we are retrocompatible with all older values.
var protocol = null;
if (bid.params.video && bid.params.video.protocol) {
protocol = bid.params.video.protocol;
} else if (Array.isArray(videoMediaType.protocols)) {
protocol = Math.max.apply(Math, videoMediaType.protocols);
}

// Default value for all exotic cases set to bid.params.video.startDelay midroll hence 2.
var startDelay = 2;
if (bid.params.video && bid.params.video.startDelay) {
startDelay = bid.params.video.startDelay
} else if (videoMediaType.startdelay == 0) {
startDelay = 1;
} else if (videoMediaType.startdelay == -1) {
startDelay = 2;
} else if (videoMediaType.startdelay == -2) {
startDelay = 3;
}

// Specific attributes for instream.
let playerSize = videoMediaType.playerSize[0];
payload.isVideo = videoMediaType.context === 'instream';
payload.mediaType = VIDEO;
payload.videoData = {
videoProtocol: bid.params.video.protocol,
videoProtocol: protocol,
playerWidth: playerSize[0],
playerHeight: playerSize[1],
adBreak: bid.params.video.startDelay || 1
adBreak: startDelay
};
} else {
return {};
Expand Down Expand Up @@ -148,7 +169,8 @@ export const spec = {
currency: response.currency,
netRevenue: response.isNetCpm,
ttl: response.ttl,
dspPixels: response.dspPixels
dspPixels: response.dspPixels,
meta: { advertiserDomains: response.adomain ? response.adomain : [] }
};

if (bidRequest.mediaType === VIDEO) {
Expand Down
248 changes: 248 additions & 0 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,130 @@ describe('Smart bid adapter tests', function () {
expect(request[0]).to.be.empty;
expect(request[1]).to.not.be.empty;
});

describe('Instream videoData meta & params tests', function () {
it('Verify videoData assigns values from meta', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'instream',
playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array...
protocols: [8, 2],
startdelay: 0
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1);
});

it('Verify videoData default values assigned', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'instream',
playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array...
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2);
});

it('Verify videoData params override meta values', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'instream',
playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array...
protocols: [8, 2],
startdelay: 0
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
video: {
protocol: 6,
startDelay: 3
}
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3);
});
});
});

describe('Outstream video tests', function () {
Expand Down Expand Up @@ -644,6 +768,130 @@ describe('Smart bid adapter tests', function () {
});
});

describe('Outstream videoData meta & params tests', function () {
it('Verify videoData assigns values from meta', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array...
protocols: [8, 2],
startdelay: 0
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid-outstream',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1);
});

it('Verify videoData default values assigned', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array...
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid-outstream',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(null);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2);
});

it('Verify videoData params override meta values', function () {
config.setConfig({
'currency': {
'adServerCurrency': 'EUR'
}
});
const request = spec.buildRequests([{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array...
protocols: [8, 2],
startdelay: 0
}
},
params: {
siteId: '1234',
pageId: '5678',
formatId: '90',
target: 'test=prebid-outstream',
bidfloor: 0.420,
buId: '7569',
appName: 'Mozilla',
ckId: 42,
video: {
protocol: 6,
startDelay: 3
}
},
requestId: 'efgh5678',
transactionId: 'zsfgzzg'
}]);

expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1');
expect(request[0]).to.have.property('method').and.to.equal('POST');
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('videoData');
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3);
});
});

describe('External ids tests', function () {
it('Verify external ids in request and ids found', function () {
config.setConfig({
Expand Down