Skip to content

Commit 6dee0e4

Browse files
krzysztofequativeszponderjanzych-smartjefftmahoney
authored andcommitted
Equativ Bid Adapter: add support for video media type (prebid#12514)
* add support of dsa * restore topics * DSA fix for UT * drafy of adapter * fixes after dev test * make world simpler * fix prev commit * return empty userSyncs array by default * adjustments * apply prettier * unit tests for Equativ adapter * add dsp user sync * add readme * body can be undef * support additional br params * remove user sync * do not send dt param * handle floors and network id * handle empty media types * get min floor * fix desc for u.t. * better name for u.t. * add u.t. for not supported media type * improve currency u.t. * SADR-6484: initial video setup for new PBJS adapter * SADR-6484: Adding logging requirement missed earlier * SADR-6484: handle ext.rewarded prop for video with new oRTBConverter * SADR-6484: test revision + not sending bid requests where video obj is empty * refactoring and u.t. * rename variable * revert changes rel. to test endpoint * revert changes rel. to test endpoint * split imp[0] into seperate requests and fix u.t. --------- Co-authored-by: Elżbieta SZPONDER <[email protected]> Co-authored-by: eszponder <[email protected]> Co-authored-by: janzych-smart <[email protected]> Co-authored-by: Jeff Mahoney <[email protected]> Co-authored-by: Jeff Mahoney <[email protected]>
1 parent cd7cdf6 commit 6dee0e4

File tree

2 files changed

+319
-116
lines changed

2 files changed

+319
-116
lines changed

modules/equativBidAdapter.js

+54-37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { BANNER } from '../src/mediaTypes.js';
1+
import { config } from '../src/config.js';
2+
import { BANNER, VIDEO } from '../src/mediaTypes.js';
23
import { getBidFloor } from '../libraries/equativUtils/equativUtils.js'
4+
import { getStorageManager } from '../src/storageManager.js';
35
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
46
import { registerBidder } from '../src/adapters/bidderFactory.js';
5-
import { getStorageManager } from '../src/storageManager.js';
6-
import { deepAccess, deepSetValue, mergeDeep } from '../src/utils.js';
7+
import { deepAccess, deepSetValue, logError, logWarn, mergeDeep } from '../src/utils.js';
78

89
/**
910
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
@@ -13,26 +14,50 @@ import { deepAccess, deepSetValue, mergeDeep } from '../src/utils.js';
1314
const BIDDER_CODE = 'equativ';
1415
const COOKIE_SYNC_ORIGIN = 'https://apps.smartadserver.com';
1516
const COOKIE_SYNC_URL = `${COOKIE_SYNC_ORIGIN}/diff/templates/asset/csync.html`;
17+
const LOG_PREFIX = 'Equativ:';
1618
const PID_COOKIE_NAME = 'eqt_pid';
1719

20+
/**
21+
* Evaluates a bid request for validity. Returns false if the
22+
* request contains a video media type with no properties, true
23+
* otherwise.
24+
* @param {*} bidReq A bid request object to evaluate
25+
* @returns boolean
26+
*/
27+
function isValid(bidReq) {
28+
return !(bidReq.mediaTypes.video && JSON.stringify(bidReq.mediaTypes.video) === '{}');
29+
}
30+
1831
export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
1932

2033
export const spec = {
2134
code: BIDDER_CODE,
2235
gvlid: 45,
23-
supportedMediaTypes: [BANNER],
36+
supportedMediaTypes: [BANNER, VIDEO],
2437

2538
/**
2639
* @param bidRequests
2740
* @param bidderRequest
2841
* @returns {ServerRequest[]}
2942
*/
3043
buildRequests: (bidRequests, bidderRequest) => {
31-
return {
32-
data: converter.toORTB({ bidderRequest, bidRequests }),
33-
method: 'POST',
34-
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169'
35-
};
44+
if (bidRequests.filter(isValid).length === 0) {
45+
logError(`${LOG_PREFIX} No useful bid requests to process. No request will be sent.`, bidRequests);
46+
return undefined;
47+
}
48+
49+
const requests = [];
50+
51+
bidRequests.forEach(bid => {
52+
const data = converter.toORTB({bidRequests: [bid], bidderRequest});
53+
requests.push({
54+
data,
55+
method: 'POST',
56+
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169',
57+
})
58+
});
59+
60+
return requests;
3661
},
3762

3863
/**
@@ -89,32 +114,23 @@ export const converter = ortbConverter({
89114

90115
imp(buildImp, bidRequest, context) {
91116
const imp = buildImp(bidRequest, context);
117+
const mediaType = deepAccess(bidRequest, 'mediaTypes.video') ? VIDEO : BANNER;
92118
const { siteId, pageId, formatId } = bidRequest.params;
93119

94120
delete imp.dt;
95121

96-
imp.bidfloor = imp.bidfloor || getBidFloor(bidRequest);
97-
imp.secure = bidRequest.ortb2Imp?.secure ?? 1;
98-
imp.tagid = bidRequest.adUnitCode;
99-
100-
if (siteId || pageId || formatId) {
101-
const bidder = {};
102-
103-
if (siteId) {
104-
bidder.siteId = siteId;
105-
}
122+
imp.bidfloor = imp.bidfloor || getBidFloor(bidRequest, config.getConfig('currency.adServerCurrency'), mediaType);
123+
imp.secure = 1;
106124

107-
if (pageId) {
108-
bidder.pageId = pageId;
109-
}
125+
imp.tagid = bidRequest.adUnitCode;
110126

111-
if (formatId) {
112-
bidder.formatId = formatId;
113-
}
127+
if (!deepAccess(bidRequest, 'ortb2Imp.rwdd') && deepAccess(bidRequest, 'mediaTypes.video.ext.rewarded')) {
128+
mergeDeep(imp, { rwdd: bidRequest.mediaTypes.video.ext.rewarded });
129+
}
114130

115-
mergeDeep(imp, {
116-
ext: { bidder },
117-
});
131+
const bidder = { ...(siteId && { siteId }), ...(pageId && { pageId }), ...(formatId && { formatId }) };
132+
if (Object.keys(bidder).length) {
133+
mergeDeep(imp.ext, { bidder });
118134
}
119135

120136
return imp;
@@ -124,14 +140,15 @@ export const converter = ortbConverter({
124140
const bid = context.bidRequests[0];
125141
const req = buildRequest(imps, bidderRequest, context);
126142

127-
if (deepAccess(bid, 'ortb2.site.publisher')) {
128-
deepSetValue(req, 'site.publisher.id', bid.ortb2.site.publisher.id || bid.params.networkId);
129-
} else if (deepAccess(bid, 'ortb2.app.publisher')) {
130-
deepSetValue(req, 'app.publisher.id', bid.ortb2.app.publisher.id || bid.params.networkId);
131-
} else if (deepAccess(bid, 'ortb2.dooh.publisher')) {
132-
deepSetValue(req, 'dooh.publisher.id', bid.ortb2.dooh.publisher.id || bid.params.networkId);
133-
} else {
134-
deepSetValue(req, 'site.publisher.id', bid.params.networkId);
143+
let env = ['ortb2.site.publisher', 'ortb2.app.publisher', 'ortb2.dooh.publisher'].find(propPath => deepAccess(bid, propPath)) || 'ortb2.site.publisher';
144+
deepSetValue(req, env.replace('ortb2.', '') + '.id', deepAccess(bid, env + '.id') || bid.params.networkId);
145+
146+
if (deepAccess(bid, 'mediaTypes.video')) {
147+
['mimes', 'placement'].forEach(prop => {
148+
if (!bid.mediaTypes.video[prop]) {
149+
logWarn(`${LOG_PREFIX} Property "${prop}" is missing from request`, bid);
150+
}
151+
});
135152
}
136153

137154
const pid = storage.getCookie(PID_COOKIE_NAME);
@@ -140,7 +157,7 @@ export const converter = ortbConverter({
140157
}
141158

142159
return req;
143-
},
160+
}
144161
});
145162

146163
registerBidder(spec);

0 commit comments

Comments
 (0)