Skip to content

Commit

Permalink
PubMatic Bid Adapter : support for InBannerVideo (IBV) Field in Bid R…
Browse files Browse the repository at this point in the history
…esponse with meta.mediaType (#12484)

Support for InBannerVideo (IBV) Field in Bid Response with meta.mediaType
  • Loading branch information
pm-nitin-shirsat authored Nov 21, 2024
1 parent 835a3d3 commit a60d667
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 6 deletions.
23 changes: 20 additions & 3 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,18 @@ function _handleEids(payload, validBidRequests) {
}
}

// Setting IBV & meta.mediaType field into the bid response
export function setIBVField(bid, newBid) {
if (bid?.ext?.ibv) {
newBid.ext = newBid.ext || {};
newBid.ext['ibv'] = bid.ext.ibv;

// Overriding the mediaType field in meta with the `video` value if bid.ext.ibv is present
newBid.meta = newBid.meta || {};
newBid.meta.mediaType = VIDEO;
}
}

function _checkMediaType(bid, newBid) {
// Create a regex here to check the strings
if (bid.ext && bid.ext['bidtype'] != undefined) {
Expand Down Expand Up @@ -1008,7 +1020,7 @@ function isNonEmptyArray(test) {
* @param {*} bid : bids
*/
export function prepareMetaObject(br, bid, seat) {
br.meta = {};
br.meta = br.meta || {};

if (bid.ext && bid.ext.dspid) {
br.meta.networkId = bid.ext.dspid;
Expand Down Expand Up @@ -1047,6 +1059,11 @@ export function prepareMetaObject(br, bid, seat) {
if (bid.ext && bid.ext.dsa && Object.keys(bid.ext.dsa).length) {
br.meta.dsa = bid.ext.dsa;
}

// Initializing meta.mediaType field to the actual bidType returned by the bidder
if (br.mediaType) {
br.meta.mediaType = br.mediaType;
}
}

export const spec = {
Expand Down Expand Up @@ -1401,12 +1418,12 @@ export const spec = {
}
});
}
prepareMetaObject(newBid, bid, seatbidder.seat);
setIBVField(bid, newBid);
if (bid.ext && bid.ext.deal_channel) {
newBid['dealChannel'] = dealChannelValues[bid.ext.deal_channel] || null;
}

prepareMetaObject(newBid, bid, seatbidder.seat);

// adserverTargeting
if (seatbidder.ext && seatbidder.ext.buyid) {
newBid.adserverTargeting = {
Expand Down
88 changes: 85 additions & 3 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject, getDeviceConnectionType } from 'modules/pubmaticBidAdapter.js';
import { spec, checkVideoPlacement, _getDomainFromURL, assignDealTier, prepareMetaObject, getDeviceConnectionType, setIBVField } from 'modules/pubmaticBidAdapter.js';
import * as utils from 'src/utils.js';
import { config } from 'src/config.js';
import { createEidsArray } from 'modules/userId/eids.js';
Expand Down Expand Up @@ -3579,6 +3579,33 @@ describe('PubMatic adapter', function () {
expect(response[0].renderer).to.not.exist;
});

it('should set ibv field in bid.ext when bid.ext.ibv exists', function() {
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});

let copyOfBidResponse = utils.deepClone(bannerBidResponse);
let bidExt = utils.deepClone(copyOfBidResponse.body.seatbid[0].bid[0].ext);
copyOfBidResponse.body.seatbid[0].bid[0].ext = Object.assign(bidExt, {
ibv: true
});

let response = spec.interpretResponse(copyOfBidResponse, request);
expect(response[0].ext.ibv).to.equal(true);
expect(response[0].meta.mediaType).to.equal('video');
});

it('should not set ibv field when bid.ext does not exist ', function() {
let request = spec.buildRequests(bidRequests, {
auctionId: 'new-auction-id'
});

let response = spec.interpretResponse(bannerBidResponse, request);
expect(response[0].ext).to.not.exist;
expect(response[0].meta).to.exist;
expect(response[0].meta.mediaType).to.equal('banner');
});

if (FEATURES.VIDEO) {
it('should check for valid video mediaType in case of multiformat request', function() {
let request = spec.buildRequests(videoBidRequests, {
Expand Down Expand Up @@ -3878,10 +3905,12 @@ describe('PubMatic adapter', function () {
// dchain: 'dc',
// demandSource: 'ds',
// secondaryCatIds: ['secondaryCatIds']
}
},
};

const br = {};
const br = {
mediaType: 'video'
};
prepareMetaObject(br, bid, null);
expect(br.meta.networkId).to.equal(6); // dspid
expect(br.meta.buyerId).to.equal('12'); // adid
Expand All @@ -3900,6 +3929,7 @@ describe('PubMatic adapter', function () {
expect(br.meta.advertiserDomains).to.be.an('array').with.length.above(0); // adomain
expect(br.meta.clickUrl).to.equal('mystartab.com'); // adomain
expect(br.meta.dsa).to.equal(dsa); // dsa
expect(br.meta.mediaType).to.equal('video'); // mediaType
});

it('Should be empty, when ext and adomain is absent in bid object', function () {
Expand Down Expand Up @@ -4176,6 +4206,58 @@ describe('PubMatic adapter', function () {
expect(data.imp[0]['banner']['battr']).to.equal(undefined);
});
});

describe('setIBVField', function() {
it('should set ibv field in newBid.ext when bid.ext.ibv exists', function() {
const bid = {
ext: {
ibv: true
}
};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.exist;
expect(newBid.ext.ibv).to.equal(true);
expect(newBid.meta).to.exist;
expect(newBid.meta.mediaType).to.equal('video');
});

it('should not set ibv field when bid.ext.ibv does not exist', function() {
const bid = {
ext: {}
};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.not.exist;
expect(newBid.meta).to.not.exist;
});

it('should not set ibv field when bid.ext does not exist', function() {
const bid = {};
const newBid = {};
setIBVField(bid, newBid);
expect(newBid.ext).to.not.exist;
expect(newBid.meta).to.not.exist;
});

it('should preserve existing newBid.ext properties', function() {
const bid = {
ext: {
ibv: true
}
};
const newBid = {
ext: {
existingProp: 'should remain'
}
};
setIBVField(bid, newBid);
expect(newBid.ext.existingProp).to.equal('should remain');
expect(newBid.ext.ibv).to.equal(true);
expect(newBid.meta).to.exist;
expect(newBid.meta.mediaType).to.equal('video');
});
});
});

if (FEATURES.VIDEO) {
Expand Down

0 comments on commit a60d667

Please sign in to comment.