Skip to content

Commit

Permalink
ZetaSspBidAdapter: provide media type (#7762)
Browse files Browse the repository at this point in the history
* provideMediaType

* checkstyle issue

Co-authored-by: Surovenko Alexey <surovenko.alexey@gmail.com>
  • Loading branch information
asurovenko-zeta and surovenko authored Nov 30, 2021
1 parent c763f7a commit a5b0d64
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
26 changes: 22 additions & 4 deletions modules/zeta_global_sspBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logWarn, deepSetValue, deepAccess, isArray, isNumber, isBoolean, isStr } from '../src/utils.js';
import {deepAccess, deepSetValue, isArray, isBoolean, isNumber, isStr, logWarn} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
Expand All @@ -11,6 +11,8 @@ const DEFAULT_CUR = 'USD';
const TTL = 200;
const NET_REV = true;

const VIDEO_REGEX = new RegExp(/VAST\s+version/);

const DATA_TYPES = {
'NUMBER': 'number',
'STRING': 'string',
Expand Down Expand Up @@ -161,9 +163,7 @@ export const spec = {
advertiserDomains: zetaBid.adomain
};
}
if (deepAccess(zetaBid, 'ext.bidtype', '') === VIDEO) {
bid.vastXml = bid.ad;
}
provideMediaType(zetaBid, bid);
bidResponses.push(bid);
})
})
Expand Down Expand Up @@ -287,4 +287,22 @@ function isConnectedTV() {
return /(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i.test(navigator.userAgent);
}

function provideMediaType(zetaBid, bid) {
if (zetaBid.ext && zetaBid.ext.bidtype) {
if (zetaBid.ext.bidtype === VIDEO) {
bid.mediaType = VIDEO;
bid.vastXml = bid.ad;
} else {
bid.mediaType = BANNER;
}
} else {
if (VIDEO_REGEX.test(bid.ad)) {
bid.mediaType = VIDEO;
bid.vastXml = bid.ad;
} else {
bid.mediaType = BANNER;
}
}
}

registerBidder(spec);
27 changes: 27 additions & 0 deletions test/spec/modules/zeta_global_sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {spec} from '../../../modules/zeta_global_sspBidAdapter.js'
import {BANNER, VIDEO} from '../../../src/mediaTypes';

describe('Zeta Ssp Bid Adapter', function () {
const eids = [
Expand Down Expand Up @@ -147,6 +148,18 @@ describe('Zeta Ssp Bid Adapter', function () {
ext: {
bidtype: 'video'
}
},
{
id: 'auctionId3',
impid: 'impId3',
price: 0.2,
adm: '<?xml version=\\"1.0\\"?><VAST version=\\"4.0\\">',
crid: 'creativeId3',
adomain: [
'https://example3.com'
],
h: 400,
w: 300
}
]
}
Expand All @@ -163,6 +176,7 @@ describe('Zeta Ssp Bid Adapter', function () {
expect(bid1).to.not.be.empty;
expect(bid1.ad).to.equal(receivedBid1.adm);
expect(bid1.vastXml).to.be.undefined;
expect(bid1.mediaType).to.equal(BANNER);
expect(bid1.cpm).to.equal(receivedBid1.price);
expect(bid1.height).to.equal(receivedBid1.h);
expect(bid1.width).to.equal(receivedBid1.w);
Expand All @@ -174,11 +188,24 @@ describe('Zeta Ssp Bid Adapter', function () {
expect(bid2).to.not.be.empty;
expect(bid2.ad).to.equal(receivedBid2.adm);
expect(bid2.vastXml).to.equal(receivedBid2.adm);
expect(bid2.mediaType).to.equal(VIDEO);
expect(bid2.cpm).to.equal(receivedBid2.price);
expect(bid2.height).to.equal(receivedBid2.h);
expect(bid2.width).to.equal(receivedBid2.w);
expect(bid2.requestId).to.equal(receivedBid2.impid);
expect(bid2.meta.advertiserDomains).to.equal(receivedBid2.adomain);

const bid3 = bidResponse[2];
const receivedBid3 = response.body.seatbid[0].bid[2];
expect(bid3).to.not.be.empty;
expect(bid3.ad).to.equal(receivedBid3.adm);
expect(bid3.vastXml).to.equal(receivedBid3.adm);
expect(bid3.mediaType).to.equal(VIDEO);
expect(bid3.cpm).to.equal(receivedBid3.price);
expect(bid3.height).to.equal(receivedBid3.h);
expect(bid3.width).to.equal(receivedBid3.w);
expect(bid3.requestId).to.equal(receivedBid3.impid);
expect(bid3.meta.advertiserDomains).to.equal(receivedBid3.adomain);
});

it('Different cases for user syncs', function () {
Expand Down

0 comments on commit a5b0d64

Please sign in to comment.