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

Smartadserver Bid Adapter: support additional video parameters #10815

Merged
merged 25 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8acd2b4
Smartadserver Bid Adapter: Add support for SDA user and site
mcourouble Nov 9, 2022
d3387b8
Merge branch 'prebid:master' into master
krzysztofequativ Nov 15, 2022
72c7169
Merge remote-tracking branch 'upstream/master'
mcourouble Nov 16, 2022
24ebad8
Smartadserver Bid Adapter: Fix SDA support getConfig and add to unit …
mcourouble Nov 16, 2022
3952d84
Merge branch 'prebid:master' into master
krzysztofequativ Jan 13, 2023
36312fd
support floors per media type
krzysztofequativ Jan 17, 2023
f7f51b6
Merge pull request #14 from smartadserver/floor-per-mediatype
krzysztofequativ Jan 18, 2023
18c659b
Merge branch 'prebid:master' into master
krzysztofequativ Jan 23, 2023
de0d762
Add GPP support
krzysztofequativ Jan 24, 2023
5b89a6e
Rework payloads enriching
krzysztofequativ Jan 24, 2023
6db82d2
Merge pull request #16 from smartadserver/floor-per-mediatype
krzysztofequativ Jan 25, 2023
f5767f7
Merge branch 'prebid:master' into master
krzysztofequativ Jan 26, 2023
9ef7251
Merge branch 'master' into gpp
krzysztofequativ Feb 1, 2023
d4dcbf9
Merge pull request #15 from smartadserver/gpp
krzysztofequativ Feb 1, 2023
fe96171
Merge branch 'prebid:master' into master
krzysztofequativ Feb 1, 2023
0a12454
Merge branch 'prebid:master' into master
krzysztofequativ Feb 2, 2023
10ee3df
Merge branch 'prebid:master' into master
krzysztofequativ May 19, 2023
7323339
Add gpid support
krzysztofequativ May 22, 2023
ebcb8e5
Merge pull request #17 from smartadserver/gpid
krzysztofequativ May 26, 2023
62a184d
Merge branch 'prebid:master' into master
krzysztofequativ Nov 30, 2023
2795791
Support additional video params
krzysztofequativ Dec 1, 2023
dd0e886
vpmt as array of numbers
krzysztofequativ Dec 6, 2023
000f8e1
Merge pull request #18 from smartadserver/video-params
krzysztofequativ Dec 11, 2023
f7d3573
Merge branch 'prebid:master' into master
krzysztofequativ Dec 11, 2023
9f5d9d2
Fix comment
krzysztofequativ Jan 3, 2024
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
47 changes: 40 additions & 7 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepAccess, deepClone, logError, isFn, isPlainObject } from '../src/utils.js';
import { deepAccess, deepClone, isArrayOfNums, isFn, isInteger, isPlainObject, logError } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -55,20 +55,53 @@ export const spec = {
* Fills the payload with specific video attributes.
*
* @param {*} payload Payload that will be sent in the ServerRequest
* @param {*} videoMediaType Video media type.
* @param {*} videoMediaType Video media type
*/
fillPayloadForVideoBidRequest: function(payload, videoMediaType, videoParams) {
const playerSize = videoMediaType.playerSize[0];
payload.isVideo = videoMediaType.context === 'instream';
const map = {
maxbitrate: 'vbrmax',
maxduration: 'vdmax',
minbitrate: 'vbrmin',
minduration: 'vdmin',
placement: 'vpt',
plcmt: 'vplcmt',
skip: 'skip'
};

payload.mediaType = VIDEO;
payload.isVideo = videoMediaType.context === 'instream';
payload.videoData = {};

for (const [key, value] of Object.entries(map)) {
payload.videoData = {
...payload.videoData,
...this.getValuableProperty(value, videoMediaType[key])
};
}

payload.videoData = {
videoProtocol: this.getProtocolForVideoBidRequest(videoMediaType, videoParams),
playerWidth: playerSize[0],
playerHeight: playerSize[1],
adBreak: this.getStartDelayForVideoBidRequest(videoMediaType, videoParams)
...payload.videoData,
...this.getValuableProperty('playerWidth', playerSize[0]),
...this.getValuableProperty('playerHeight', playerSize[1]),
...this.getValuableProperty('adBreak', this.getStartDelayForVideoBidRequest(videoMediaType, videoParams)),
...this.getValuableProperty('videoProtocol', this.getProtocolForVideoBidRequest(videoMediaType, videoParams)),
...(isArrayOfNums(videoMediaType.api) && videoMediaType.api.length ? { iabframeworks: videoMediaType.api.toString() } : {}),
...(isArrayOfNums(videoMediaType.playbackmethod) && videoMediaType.playbackmethod.length ? { vpmt: videoMediaType.playbackmethod } : {})
};
},

/**
* Gets a property object if the value not falsy
* @param {string} property
* @param {number} value
* @returns object with the property or empty
*/
getValuableProperty: function(property, value) {
return typeof property === 'string' && isInteger(value) && value
? { [property]: value } : {};
},

/**
* Gets the protocols from either videoParams or VideoMediaType
* @param {*} videoMediaType
Expand Down
108 changes: 106 additions & 2 deletions test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ describe('Smart bid adapter tests', function () {
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).not.to.have.property('videoProtocol').eq(true);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2);
});

Expand Down Expand Up @@ -833,6 +833,73 @@ describe('Smart bid adapter tests', function () {
expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3);
});

it('should pass additional parameters', function () {
const request = spec.buildRequests([{
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'instream',
api: [1, 2, 3],
maxbitrate: 50,
minbitrate: 20,
maxduration: 30,
minduration: 5,
placement: 3,
playbackmethod: [2, 4],
playerSize: [[640, 480]],
plcmt: 1,
skip: 0
}
},
params: {
siteId: '123'
}
}]);
const requestContent = JSON.parse(request[0].data);

expect(requestContent.videoData).to.have.property('iabframeworks').and.to.equal('1,2,3');
expect(requestContent.videoData).not.to.have.property('skip');
expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(50);
expect(requestContent.videoData).to.have.property('vbrmin').and.to.equal(20);
expect(requestContent.videoData).to.have.property('vdmax').and.to.equal(30);
expect(requestContent.videoData).to.have.property('vdmin').and.to.equal(5);
expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1);
expect(requestContent.videoData).to.have.property('vpmt').and.to.have.lengthOf(2);
expect(requestContent.videoData.vpmt[0]).to.equal(2);
expect(requestContent.videoData.vpmt[1]).to.equal(4);
expect(requestContent.videoData).to.have.property('vpt').and.to.equal(3);
});

it('should not pass not valuable parameters', function () {
const request = spec.buildRequests([{
bidder: 'smartadserver',
mediaTypes: {
video: {
context: 'instream',
maxbitrate: 20,
minbitrate: null,
maxduration: 0,
playbackmethod: [],
playerSize: [[640, 480]],
plcmt: 1
}
},
params: {
siteId: '123'
}
}]);
const requestContent = JSON.parse(request[0].data);

expect(requestContent.videoData).not.to.have.property('iabframeworks');
expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(20);
expect(requestContent.videoData).not.to.have.property('vbrmin');
expect(requestContent.videoData).not.to.have.property('vdmax');
expect(requestContent.videoData).not.to.have.property('vdmin');
expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1);
expect(requestContent.videoData).not.to.have.property('vpmt');
expect(requestContent.videoData).not.to.have.property('vpt');
});
});
});

Expand Down Expand Up @@ -1029,7 +1096,7 @@ describe('Smart bid adapter tests', function () {
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).not.to.have.property('videoProtocol').eq(true);
expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2);
});

Expand Down Expand Up @@ -1393,4 +1460,41 @@ describe('Smart bid adapter tests', function () {
expect(requestContent).to.have.property('gpid').and.to.equal(gpid);
});
});

describe('#getValuableProperty method', function () {
it('should return an object when calling with a number value', () => {
const obj = spec.getValuableProperty('prop', 3);
expect(obj).to.deep.equal({ prop: 3 });
});

it('should return an empty object when calling with a string value', () => {
const obj = spec.getValuableProperty('prop', 'str');
expect(obj).to.deep.equal({});
});

it('should return an empty object when calling with a number property', () => {
const obj = spec.getValuableProperty(7, 'str');
expect(obj).to.deep.equal({});
});

it('should return an empty object when calling with a null value', () => {
const obj = spec.getValuableProperty('prop', null);
expect(obj).to.deep.equal({});
});

it('should return an empty object when calling with an object value', () => {
const obj = spec.getValuableProperty('prop', {});
expect(obj).to.deep.equal({});
});

it('should return an empty object when calling with a 0 value', () => {
const obj = spec.getValuableProperty('prop', 0);
expect(obj).to.deep.equal({});
});

it('should return an empty object when calling without the value argument', () => {
const obj = spec.getValuableProperty('prop');
expect(obj).to.deep.equal({});
});
});
});