Skip to content

Commit

Permalink
Merge pull request #34 from smartadserver/SADR-6484
Browse files Browse the repository at this point in the history
Publish video support
  • Loading branch information
krzysztofequativ authored Nov 27, 2024
2 parents 62307a3 + f35f424 commit 65905e0
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 89 deletions.
70 changes: 39 additions & 31 deletions modules/equativBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BANNER } from '../src/mediaTypes.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { getBidFloor } from '../libraries/equativUtils/equativUtils.js'
import { getStorageManager } from '../src/storageManager.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import { deepAccess, deepSetValue, mergeDeep } from '../src/utils.js';
import { deepAccess, deepSetValue, logError, logWarn, mergeDeep } from '../src/utils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
Expand All @@ -13,25 +13,43 @@ import { deepAccess, deepSetValue, mergeDeep } from '../src/utils.js';
const BIDDER_CODE = 'equativ';
const COOKIE_SYNC_ORIGIN = 'https://apps.smartadserver.com';
const COOKIE_SYNC_URL = `${COOKIE_SYNC_ORIGIN}/diff/templates/asset/csync.html`;
const LOG_PREFIX = 'Equativ:';
const PID_COOKIE_NAME = 'eqt_pid';

/**
* Evaluates a bid request for validity. Returns false if the
* request contains a video media type with no properties, true
* otherwise.
* @param {*} bidReq A bid request object to evaluate
* @returns boolean
*/
function isValid(bidReq) {
return !(bidReq.mediaTypes.video && JSON.stringify(bidReq.mediaTypes.video) === '{}');
}

export const storage = getStorageManager({ bidderCode: BIDDER_CODE });

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

/**
* @param bidRequests
* @param bidderRequest
* @returns {ServerRequest[]}
*/
buildRequests: (bidRequests, bidderRequest) => {
if (bidRequests.filter(isValid).length === 0) {
logError(`${LOG_PREFIX} No useful bid requests to process. No request will be sent.`, bidRequests);
return undefined;
}

return {
data: converter.toORTB({ bidderRequest, bidRequests }),
method: 'POST',
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169'
// url: 'https://ssb-engine-argocd-dev.internal.smartadserver.com/api/bid?callerId=169'
url: 'https://ssb-global.smartadserver.com/api/bid?callerId=169',
};
},

Expand Down Expand Up @@ -97,24 +115,13 @@ export const converter = ortbConverter({
imp.secure = 1;
imp.tagid = bidRequest.adUnitCode;

if (siteId || pageId || formatId) {
const bidder = {};

if (siteId) {
bidder.siteId = siteId;
}

if (pageId) {
bidder.pageId = pageId;
}

if (formatId) {
bidder.formatId = formatId;
}
if (!deepAccess(bidRequest, 'ortb2Imp.rwdd') && deepAccess(bidRequest, 'mediaTypes.video.ext.rewarded')) {
mergeDeep(imp, { rwdd: bidRequest.mediaTypes.video.ext.rewarded });
}

mergeDeep(imp, {
ext: { bidder },
});
const bidder = { ...(siteId && { siteId }), ...(pageId && { pageId }), ...(formatId && { formatId }) };
if (Object.keys(bidder).length) {
mergeDeep(imp.ext, { bidder });
}

return imp;
Expand All @@ -124,14 +131,15 @@ export const converter = ortbConverter({
const bid = context.bidRequests[0];
const req = buildRequest(imps, bidderRequest, context);

if (deepAccess(bid, 'ortb2.site.publisher')) {
deepSetValue(req, 'site.publisher.id', bid.ortb2.site.publisher.id || bid.params.networkId);
} else if (deepAccess(bid, 'ortb2.app.publisher')) {
deepSetValue(req, 'app.publisher.id', bid.ortb2.app.publisher.id || bid.params.networkId);
} else if (deepAccess(bid, 'ortb2.dooh.publisher')) {
deepSetValue(req, 'dooh.publisher.id', bid.ortb2.dooh.publisher.id || bid.params.networkId);
} else {
deepSetValue(req, 'site.publisher.id', bid.params.networkId);
let env = ['ortb2.site.publisher', 'ortb2.app.publisher', 'ortb2.dooh.publisher'].find(propPath => deepAccess(bid, propPath)) || 'ortb2.site.publisher';
deepSetValue(req, env.replace('ortb2.', '') + '.id', deepAccess(bid, env + '.id') || bid.params.networkId);

if (deepAccess(bid, 'mediaTypes.video')) {
['mimes', 'placement'].forEach(prop => {
if (!bid.mediaTypes.video[prop]) {
logWarn(`${LOG_PREFIX} Property "${prop}" is missing from request`, bid);
}
});
}

const pid = storage.getCookie(PID_COOKIE_NAME);
Expand All @@ -140,7 +148,7 @@ export const converter = ortbConverter({
}

return req;
},
}
});

registerBidder(spec);
Loading

0 comments on commit 65905e0

Please sign in to comment.