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

Prebid 7: TheMediaGrid: make trustxBidAdapter as alias of gridBidAdapter #8321

Merged
merged 5 commits into from
May 18, 2022
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
59 changes: 46 additions & 13 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ const LOG_ERROR_MESS = {
hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - '
};

const ALIAS_CONFIG = {
'trustx': {
endpoint: 'https://grid.bidswitch.net/hbjson?sp=trustx',
syncurl: 'https://x.bidswitch.net/sync?ssp=themediagrid',
bidResponseExternal: {
netRevenue: false
}
}
};

let hasSynced = false;

export const spec = {
code: BIDDER_CODE,
aliases: ['playwire', 'adlivetech'],
aliases: ['playwire', 'adlivetech', 'trustx'],
supportedMediaTypes: [ BANNER, VIDEO ],
/**
* Determines whether or not the given bid request is valid.
Expand Down Expand Up @@ -58,6 +68,8 @@ export const spec = {
let userIdAsEids = null;
let user = null;
let userExt = null;
let endpoint = null;
let forceBidderName = false;
let {bidderRequestId, auctionId, gdprConsent, uspConsent, timeout, refererInfo} = bidderRequest || {};

const referer = refererInfo ? encodeURIComponent(refererInfo.referer) : '';
Expand All @@ -77,7 +89,10 @@ export const spec = {
if (!userIdAsEids) {
userIdAsEids = bid.userIdAsEids;
}
const {params: {uid, keywords}, mediaTypes, bidId, adUnitCode, rtd, ortb2Imp} = bid;
if (!endpoint) {
endpoint = ALIAS_CONFIG[bid.bidder] && ALIAS_CONFIG[bid.bidder].endpoint;
}
const { params: { uid, keywords, forceBidder }, mediaTypes, bidId, adUnitCode, rtd, ortb2Imp } = bid;
bidsMap[bidId] = bid;
const bidFloor = _getFloor(mediaTypes || {}, bid);
const jwTargeting = rtd && rtd.jwplayer && rtd.jwplayer.targeting;
Expand Down Expand Up @@ -136,8 +151,19 @@ export const spec = {
if (impObj.banner || impObj.video) {
imp.push(impObj);
}

if (!forceBidderName && forceBidder && ALIAS_CONFIG[forceBidder]) {
forceBidderName = forceBidder;
}
});

forceBidderName = config.getConfig('forceBidderName') || forceBidderName;
patmmccann marked this conversation as resolved.
Show resolved Hide resolved

if (forceBidderName && ALIAS_CONFIG[forceBidderName]) {
endpoint = ALIAS_CONFIG[forceBidderName].endpoint;
this.forceBidderName = forceBidderName;
}

const source = {
tid: auctionId && auctionId.toString(),
ext: {
Expand Down Expand Up @@ -293,9 +319,8 @@ export const spec = {

return {
method: 'POST',
url: ENDPOINT_URL,
url: endpoint || ENDPOINT_URL,
data: JSON.stringify(request),
newFormat: true,
bidsMap
};
},
Expand All @@ -304,9 +329,10 @@ export const spec = {
*
* @param {*} serverResponse A successful response from the server.
* @param {*} bidRequest
* @param {*} RendererConst
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
interpretResponse: function(serverResponse, bidRequest, RendererConst = Renderer) {
serverResponse = serverResponse && serverResponse.body;
const bidResponses = [];

Expand All @@ -317,15 +343,18 @@ export const spec = {
errorMessage = LOG_ERROR_MESS.hasEmptySeatbidArray;
}

const bidderCode = this.forceBidderName || this.code;

if (!errorMessage && serverResponse.seatbid) {
serverResponse.seatbid.forEach(respItem => {
_addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses);
_addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses, RendererConst, bidderCode);
});
}
if (errorMessage) logError(errorMessage);
return bidResponses;
},
getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
getUserSyncs: function (...args) {
const [syncOptions,, gdprConsent, uspConsent] = args;
if (!hasSynced && syncOptions.pixelEnabled) {
let params = '';

Expand All @@ -341,10 +370,13 @@ export const spec = {
params += `&us_privacy=${uspConsent}`;
}

const bidderCode = this.forceBidderName || this.code;
const syncUrl = (ALIAS_CONFIG[bidderCode] && ALIAS_CONFIG[bidderCode].syncurl) || SYNC_URL;

hasSynced = true;
return {
type: 'image',
url: SYNC_URL + params
url: syncUrl + params
};
}
}
Expand Down Expand Up @@ -388,7 +420,7 @@ function _getBidFromResponse(respItem) {
return respItem && respItem.bid && respItem.bid[0];
}

function _addBidResponse(serverBid, bidRequest, bidResponses) {
function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst, bidderCode) {
if (!serverBid) return;
let errorMessage;
if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid);
Expand Down Expand Up @@ -430,13 +462,14 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) {
bidResponse.renderer = createRenderer(bidResponse, {
id: bid.bidId,
url: RENDERER_URL
});
}, RendererConst);
}
} else {
bidResponse.ad = serverBid.adm;
bidResponse.mediaType = BANNER;
}
bidResponses.push(bidResponse);
const bidResponseExternal = (ALIAS_CONFIG[bidderCode] && ALIAS_CONFIG[bidderCode].bidResponseExternal) || {};
bidResponses.push(mergeDeep(bidResponse, bidResponseExternal));
}
}
if (errorMessage) {
Expand Down Expand Up @@ -564,8 +597,8 @@ function outstreamRender (bid) {
});
}

function createRenderer (bid, rendererParams) {
const renderer = Renderer.install({
function createRenderer (bid, rendererParams, RendererConst) {
const renderer = RendererConst.install({
id: rendererParams.id,
url: rendererParams.url,
loaded: false
Expand Down
Loading