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

Insticator Bid adapter: Adds Support for Video #8452

Merged
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
151 changes: 109 additions & 42 deletions modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {config} from '../src/config.js';
import {BANNER} from '../src/mediaTypes.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {deepAccess, generateUUID, logError, isArray} from '../src/utils.js';
import {getStorageManager} from '../src/storageManager.js';
Expand Down Expand Up @@ -48,14 +48,9 @@ function setUserId(userId) {
}
}

function buildImpression(bidRequest) {
function buildBanner(bidRequest) {
const format = [];
const ext = {
insticator: {
adUnitId: bidRequest.params.adUnitId,
},
}

const pos = deepAccess(bidRequest, 'mediaTypes.banner.pos');
const sizes =
deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes;

Expand All @@ -66,27 +61,47 @@ function buildImpression(bidRequest) {
});
}

const gpid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid');

if (gpid) {
ext.gpid = gpid;
return {
format,
pos,
}
}

const instl = deepAccess(bidRequest, 'ortb2Imp.instl')
const secure = location.protocol === 'https:' ? 1 : 0;
const pos = deepAccess(bidRequest, 'mediaTypes.banner.pos');
function buildVideo(bidRequest) {
const w = deepAccess(bidRequest, 'mediaTypes.video.w');
const h = deepAccess(bidRequest, 'mediaTypes.video.h');
const mimes = deepAccess(bidRequest, 'mediaTypes.video.mimes');

return {
mimes,
w,
h,
}
}

function buildImpression(bidRequest) {
const imp = {
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode,
instl,
secure,
banner: {
format,
pos,
instl: deepAccess(bidRequest, 'ortb2Imp.instl'),
secure: location.protocol === 'https:' ? 1 : 0,
ext: {
gpid: deepAccess(bidRequest, 'ortb2Imp.ext.gpid'),
insticator: {
adUnitId: bidRequest.params.adUnitId,
},
},
ext,
};
}

if (deepAccess(bidRequest, 'mediaTypes.banner')) {
imp.banner = buildBanner(bidRequest);
}

if (deepAccess(bidRequest, 'mediaTypes.video')) {
imp.video = buildVideo(bidRequest);
}

return imp;
}

function buildDevice() {
Expand Down Expand Up @@ -252,31 +267,83 @@ function validateSizes(sizes) {
);
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
function validateAdUnitId(bid) {
if (!bid.params.adUnitId) {
logError('insticator: missing adUnitId bid parameter');
return false;
}

isBidRequestValid: function (bid) {
if (!bid.params.adUnitId) {
logError('insticator: missing adUnitId bid parameter');
return false;
}
return true;
}

if (!(BANNER in bid.mediaTypes)) {
logError('insticator: expected banner in mediaTypes');
return false;
}
function validateMediaType(bid) {
if (!(BANNER in bid.mediaTypes || VIDEO in bid.mediaTypes)) {
logError('insticator: expected banner or video in mediaTypes');
return false;
}

if (
!validateSizes(bid.sizes) &&
!validateSizes(bid.mediaTypes.banner.sizes)
) {
logError('insticator: banner sizes not specified or invalid');
return false;
}
return true;
}

function validateBanner(bid) {
const banner = deepAccess(bid, 'mediaTypes.banner');

if (banner === undefined) {
return true;
}

if (
!validateSizes(bid.sizes) &&
!validateSizes(bid.mediaTypes.banner.sizes)
) {
logError('insticator: banner sizes not specified or invalid');
return false;
}

return true;
}

function validateVideo(bid) {
const video = deepAccess(bid, 'mediaTypes.video');

if (video === undefined) {
return true;
}

const videoSize = [
deepAccess(bid, 'mediaTypes.video.w'),
deepAccess(bid, 'mediaTypes.video.h'),
];

if (
!validateSize(videoSize)
lksharma marked this conversation as resolved.
Show resolved Hide resolved
lksharma marked this conversation as resolved.
Show resolved Hide resolved
) {
logError('insticator: video size not specified or invalid');
return false;
}

const mimes = deepAccess(bid, 'mediaTypes.video.mimes');

if (!Array.isArray(mimes) || mimes.length === 0) {
logError('insticator: mimes not specified');
return false;
}

return true;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [ BANNER, VIDEO ],

isBidRequestValid: function (bid) {
return (
validateAdUnitId(bid) &&
validateMediaType(bid) &&
validateBanner(bid) &&
validateVideo(bid)
);
},

buildRequests: function (validBidRequests, bidderRequest) {
Expand Down
47 changes: 46 additions & 1 deletion test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ describe('InsticatorBidAdapter', function () {
banner: {
sizes: [[300, 250], [300, 600]],
pos: 4,
}
},
video: {
mimes: [
'video/mp4',
'video/mpeg',
],
w: 250,
h: 300,
},
},
bidId: '30b31c1838de1e',
ortb2Imp: {
Expand Down Expand Up @@ -116,6 +124,35 @@ describe('InsticatorBidAdapter', function () {
bidRequest.mediaTypes.banner.sizes = [[300, 250], [300, 600]];
expect(spec.isBidRequestValid({ ...bidRequest, ...{ sizes: {} } })).to.be.true;
});

it('should return true if there is video and video sizes', () => {
expect(spec.isBidRequestValid({
...bidRequest,
...{
mediaTypes: {
video: {
mimes: [
'video/mp4',
'video/mpeg',
],
w: 250,
h: 300,
},
}
}
})).to.be.true;
});

it('should return false if there is no video sizes', () => {
expect(spec.isBidRequestValid({
...bidRequest,
...{
mediaTypes: {
video: {},
}
}
})).to.be.false;
});
});

describe('buildRequests', function () {
Expand Down Expand Up @@ -240,6 +277,14 @@ describe('InsticatorBidAdapter', function () {
{ w: 300, h: 600 },
]
},
video: {
mimes: [
'video/mp4',
'video/mpeg',
],
h: 300,
w: 250,
},
ext: {
gpid: bidRequest.ortb2Imp.ext.gpid,
insticator: {
Expand Down