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

Yahoo Bid Adapter: Rebrand to Yahoo Advertising #10125

Merged
merged 8 commits into from
Jul 10, 2023
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
71 changes: 38 additions & 33 deletions modules/yahoosspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Renderer } from '../src/Renderer.js';
import {hasPurpose1Consent} from '../src/utils/gpdr.js';

const INTEGRATION_METHOD = 'prebid.js';
const BIDDER_CODE = 'yahoossp';
const BIDDER_CODE = 'yahooAds';
const BIDDER_ALIASES = ['yahoossp', 'yahooAdvertising']
const GVLID = 25;
const ADAPTER_VERSION = '1.0.2';
const ADAPTER_VERSION = '1.1.0';
const PREBID_VERSION = '$prebid.version$';
const DEFAULT_BID_TTL = 300;
const TEST_MODE_DCN = '8a969516017a7a396ec539d97f540011';
Expand Down Expand Up @@ -49,13 +50,17 @@ const SUPPORTED_USER_ID_SOURCES = [
'quantcast.com',
'tapad.com',
'uidapi.com',
'verizonmedia.com',
'yahoo.com',
'zeotap.com'
];

/* Utility functions */

function getConfigValue(bid, key) {
const bidderCode = bid.bidder || bid.bidderCode;
return config.getConfig(`${bidderCode}.${key}`);
}

function getSize(size) {
return {
w: parseInt(size[0]),
Expand Down Expand Up @@ -114,11 +119,12 @@ function extractUserSyncUrls(syncOptions, pixels) {
*/
function updateConsentQueryParams(url, consentData) {
const parameterMap = {
'gdpr_consent': consentData.gdpr.consentString,
'gdpr': consentData.gdpr.gdprApplies ? '1' : '0',
'us_privacy': consentData.uspConsent,
'gpp': consentData.gpp.gppString,
'gpp_sid': consentData.gpp.applicableSections ? consentData.gpp.applicableSections.join(',') : ''
'gdpr_consent': consentData.gdpr ? consentData.gdpr.consentString : '',
'gdpr': consentData.gdpr && consentData.gdpr.gdprApplies ? '1' : '0',
'us_privacy': consentData.uspConsent ? consentData.uspConsent : '',
'gpp': consentData.gpp ? consentData.gpp.gppString : '',
'gpp_sid': consentData.gpp && Array.isArray(consentData.gpp.applicableSections)
? consentData.gpp.applicableSections.join(',') : ''
}

const existingUrl = new URL(url);
Expand Down Expand Up @@ -155,8 +161,8 @@ function getPubIdMode(bid) {
return pubIdMode;
};

function getAdapterMode() {
let adapterMode = config.getConfig('yahoossp.mode');
function getAdapterMode(bid) {
let adapterMode = getConfigValue(bid, 'mode');
adapterMode = adapterMode ? adapterMode.toLowerCase() : undefined;
if (typeof adapterMode === 'undefined' || adapterMode === BANNER) {
return BANNER;
Expand All @@ -177,7 +183,7 @@ function getResponseFormat(bid) {
};

function getFloorModuleData(bid) {
const adapterMode = getAdapterMode();
const adapterMode = getAdapterMode(bid);
const getFloorRequestObject = {
currency: deepAccess(bid, 'params.bidOverride.cur') || DEFAULT_CURRENCY,
mediaType: adapterMode,
Expand All @@ -187,7 +193,7 @@ function getFloorModuleData(bid) {
};

function filterBidRequestByMode(validBidRequests) {
const mediaTypesMode = getAdapterMode();
const mediaTypesMode = getAdapterMode(validBidRequests[0]);
let result = [];
if (mediaTypesMode === BANNER) {
result = validBidRequests.filter(bid => {
Expand Down Expand Up @@ -244,7 +250,7 @@ function validateAppendObject(validationType, allowedKeys, inputObject, appendTo
};

function getTtl(bidderRequest) {
const globalTTL = config.getConfig('yahoossp.ttl');
const globalTTL = getConfigValue(bidderRequest, 'ttl');
return globalTTL ? validateTTL(globalTTL) : validateTTL(deepAccess(bidderRequest, 'params.ttl'));
};

Expand Down Expand Up @@ -276,8 +282,8 @@ function generateOpenRtbObject(bidderRequest, bid) {
ext: {
'us_privacy': bidderRequest.uspConsent ? bidderRequest.uspConsent : '',
gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
gpp: bidderRequest.gppConsent.gppString,
gpp_sid: bidderRequest.gppConsent.applicableSections
gpp: bidderRequest.gppConsent ? bidderRequest.gppConsent.gppString : '',
gpp_sid: bidderRequest.gppConsent ? bidderRequest.gppConsent.applicableSections : []
}
},
source: {
Expand Down Expand Up @@ -332,7 +338,7 @@ function generateOpenRtbObject(bidderRequest, bid) {
};

function appendImpObject(bid, openRtbObject) {
const mediaTypeMode = getAdapterMode();
const mediaTypeMode = getAdapterMode(bid);

if (openRtbObject && bid) {
const impObject = {
Expand Down Expand Up @@ -494,20 +500,21 @@ function appendFirstPartyData(outBoundBidRequest, bid) {

function generateServerRequest({payload, requestOptions, bidderRequest}) {
const pubIdMode = getPubIdMode(bidderRequest);
let sspEndpoint = config.getConfig('yahoossp.endpoint') || SSP_ENDPOINT_DCN_POS;
const overrideEndpoint = getConfigValue(bidderRequest, 'endpoint');
let sspEndpoint = overrideEndpoint || SSP_ENDPOINT_DCN_POS;

if (pubIdMode === true) {
sspEndpoint = config.getConfig('yahoossp.endpoint') || SSP_ENDPOINT_PUBID;
sspEndpoint = overrideEndpoint || SSP_ENDPOINT_PUBID;
};

if (deepAccess(bidderRequest, 'params.testing.e2etest') === true) {
logInfo('yahoossp adapter e2etest mode is active');
logInfo('Adapter e2etest mode is active');
requestOptions.withCredentials = false;

if (pubIdMode === true) {
payload.site.id = TEST_MODE_PUBID_DCN;
} else {
const mediaTypeMode = getAdapterMode();
const mediaTypeMode = getAdapterMode(bidderRequest);
payload.site.id = TEST_MODE_DCN;
payload.imp.forEach(impObject => {
impObject.ext.e2eTestMode = true;
Expand All @@ -516,8 +523,9 @@ function generateServerRequest({payload, requestOptions, bidderRequest}) {
} else if (mediaTypeMode === VIDEO) {
impObject.tagid = TEST_MODE_VIDEO_POS; // video passback
} else {
logWarn('yahoossp adapter e2etest mode does not support yahoossp.mode="all". \n Please specify either "banner" or "video"');
logWarn('yahoossp adapter e2etest mode: Please make sure your adUnit matches the yahoossp.mode video or banner');
const bidderCode = bidderRequest.bidderCode;
logWarn(`e2etest mode does not support ${bidderCode}.mode="all". \n Please specify either "banner" or "video"`);
logWarn(`Adapter e2etest mode: Please make sure your adUnit matches the ${bidderCode}.mode video or banner`);
}
});
}
Expand All @@ -528,7 +536,7 @@ function generateServerRequest({payload, requestOptions, bidderRequest}) {
method: 'POST',
data: payload,
options: requestOptions,
bidderRequest: bidderRequest
bidderRequest // Additional data for use in interpretResponse()
};
};

Expand All @@ -547,7 +555,7 @@ function createRenderer(bidderRequest, bidResponse) {
}, deepAccess(bidderRequest, 'params.testing.renderer.setTimeout') || DEFAULT_RENDERER_TIMEOUT);
});
} catch (error) {
logWarn('yahoossp renderer error: setRender() failed', error);
logWarn('Renderer error: setRender() failed', error);
}
return renderer;
}
Expand All @@ -557,7 +565,7 @@ function createRenderer(bidderRequest, bidResponse) {
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
aliases: [],
aliases: BIDDER_ALIASES,
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function(bid) {
Expand All @@ -570,14 +578,14 @@ export const spec = {
) {
return true;
} else {
logWarn('yahoossp bidder params missing or incorrect, please pass object with either: dcn & pos OR pubId');
logWarn('Bidder params missing or incorrect, please pass object with either: dcn & pos OR pubId');
return false;
}
},

buildRequests: function(validBidRequests, bidderRequest) {
if (isEmpty(validBidRequests) || isEmpty(bidderRequest)) {
logWarn('yahoossp Adapter: buildRequests called with either empty "validBidRequests" or "bidderRequest"');
logWarn('buildRequests called with either empty "validBidRequests" or "bidderRequest"');
return undefined;
};

Expand All @@ -592,13 +600,12 @@ export const spec = {

const filteredBidRequests = filterBidRequestByMode(validBidRequests);

if (config.getConfig('yahoossp.singleRequestMode') === true) {
if (getConfigValue(bidderRequest, 'singleRequestMode') === true) {
const payload = generateOpenRtbObject(bidderRequest, filteredBidRequests[0]);
filteredBidRequests.forEach(bid => {
appendImpObject(bid, payload);
});

return generateServerRequest({payload, requestOptions, bidderRequest});
return [generateServerRequest({payload, requestOptions, bidderRequest})];
}

return filteredBidRequests.map(bid => {
Expand All @@ -608,12 +615,11 @@ export const spec = {
});
},

interpretResponse: function(serverResponse, { data, bidderRequest }) {
interpretResponse: function(serverResponse, { bidderRequest }) {
const response = [];
if (!serverResponse.body || !Array.isArray(serverResponse.body.seatbid)) {
return response;
}

let seatbids = serverResponse.body.seatbid;
seatbids.forEach(seatbid => {
let bid;
Expand All @@ -628,7 +634,6 @@ export const spec = {

let bidResponse = {
adId: deepAccess(bid, 'adId') ? bid.adId : bid.impid || bid.crid,
adUnitCode: bidderRequest.adUnitCode,
requestId: bid.impid,
cpm: cpm,
width: bid.w,
Expand Down
Loading