Skip to content

Commit

Permalink
PAAPI: emit addComponentAuction event
Browse files Browse the repository at this point in the history
Component Auction Configs appear to be entirely contained within the
PAAPI + fledgeForGPT modules. This event provides a way to access
those configs from outside of those 2 modules.
  • Loading branch information
ETNOL committed Apr 15, 2024
1 parent 2fd1b74 commit 10d9439
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 71 deletions.
53 changes: 27 additions & 26 deletions src/adapters/bidderFactory.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Adapter from '../adapter.js';
import adapterManager from '../adapterManager.js';
import {config} from '../config.js';
import {createBid} from '../bidfactory.js';
import {userSync} from '../userSync.js';
import {nativeBidIsValid} from '../native.js';
import {isValidVideoBid} from '../video.js';
import { config } from '../config.js';
import { createBid } from '../bidfactory.js';
import { userSync } from '../userSync.js';
import { nativeBidIsValid } from '../native.js';
import { isValidVideoBid } from '../video.js';
import CONSTANTS from '../constants.json';
import * as events from '../events.js';
import {includes} from '../polyfill.js';
import { includes } from '../polyfill.js';
import {
delayExecution,
isArray,
Expand All @@ -18,14 +18,14 @@ import {
parseSizesInput, pick,
uniques
} from '../utils.js';
import {hook} from '../hook.js';
import {auctionManager} from '../auctionManager.js';
import {bidderSettings} from '../bidderSettings.js';
import {useMetrics} from '../utils/perfMetrics.js';
import {isActivityAllowed} from '../activities/rules.js';
import {activityParams} from '../activities/activityParams.js';
import {MODULE_TYPE_BIDDER} from '../activities/modules.js';
import {ACTIVITY_TRANSMIT_TID, ACTIVITY_TRANSMIT_UFPD} from '../activities/activities.js';
import { hook } from '../hook.js';
import { auctionManager } from '../auctionManager.js';
import { bidderSettings } from '../bidderSettings.js';
import { useMetrics } from '../utils/perfMetrics.js';
import { isActivityAllowed } from '../activities/rules.js';
import { activityParams } from '../activities/activityParams.js';
import { MODULE_TYPE_BIDDER } from '../activities/modules.js';
import { ACTIVITY_TRANSMIT_TID, ACTIVITY_TRANSMIT_UFPD } from '../activities/activities.js';

/**
* @typedef {import('../mediaTypes.js').MediaType} MediaType
Expand Down Expand Up @@ -211,7 +211,7 @@ export function guardTids(bidderCode) {
.forEach(([prop, fn]) => proxy[prop] = fn.bind(target));
return proxy;
}
const bidRequest = memoize((br) => privateAccessProxy(br, {get}), (arg) => arg.bidId);
const bidRequest = memoize((br) => privateAccessProxy(br, { get }), (arg) => arg.bidId);
/**
* Return a view on bidd(er) requests where auctionId/transactionId are nulled if the bidder is not allowed `transmitTid`.
*
Expand All @@ -238,11 +238,11 @@ export function guardTids(bidderCode) {
*/
export function newBidder(spec) {
return Object.assign(new Adapter(spec.code), {
getSpec: function() {
getSpec: function () {
return Object.freeze(Object.assign({}, spec));
},
registerSyncs,
callBids: function(bidderRequest, addBidResponse, done, ajax, onTimelyResponse, configEnabledCallback) {
callBids: function (bidderRequest, addBidResponse, done, ajax, onTimelyResponse, configEnabledCallback) {
if (!Array.isArray(bidderRequest.bids)) {
return;
}
Expand Down Expand Up @@ -388,7 +388,7 @@ function getPaapiConfigs(adapterResponse) {
* @param onBid {function({})} invoked once for each bid in the response - with the bid as returned by interpretResponse
* @param onCompletion {function()} invoked once when all bid requests have been processed
*/
export const processBidderRequests = hook('sync', function (spec, bids, bidderRequest, ajax, wrapCallback, {onRequest, onResponse, onPaapi, onError, onBid, onCompletion}) {
export const processBidderRequests = hook('sync', function (spec, bids, bidderRequest, ajax, wrapCallback, { onRequest, onResponse, onPaapi, onError, onBid, onCompletion }) {
const metrics = adapterMetrics(bidderRequest);
onCompletion = metrics.startTiming('total').stopBefore(onCompletion);

Expand All @@ -413,7 +413,7 @@ export const processBidderRequests = hook('sync', function (spec, bids, bidderRe
// If the server responds successfully, use the adapter code to unpack the Bids from it.
// If the adapter code fails, no bids should be added. After all the bids have been added,
// make sure to call the `requestDone` function so that we're one step closer to calling onCompletion().
const onSuccess = wrapCallback(function(response, responseObj) {
const onSuccess = wrapCallback(function (response, responseObj) {
networkDone();
try {
response = JSON.parse(response);
Expand Down Expand Up @@ -528,7 +528,7 @@ export const processBidderRequests = hook('sync', function (spec, bids, bidderRe
})
}, 'processBidderRequests')

export const registerSyncInner = hook('async', function(spec, responses, gdprConsent, uspConsent, gppConsent) {
export const registerSyncInner = hook('async', function (spec, responses, gdprConsent, uspConsent, gppConsent) {
const aliasSyncEnabled = config.getConfig('userSync.aliasSyncEnabled');
if (spec.getUserSyncs && (aliasSyncEnabled || !adapterManager.aliasRegistry[spec.code])) {
let filterConfig = config.getConfig('userSync.filterSettings');
Expand All @@ -549,10 +549,11 @@ export const registerSyncInner = hook('async', function(spec, responses, gdprCon
}, 'registerSyncs')

export const addComponentAuction = hook('sync', (request, fledgeAuctionConfig) => {
events.emit(CONSTANTS.EVENTS.ADD_COMPONENT_AUCTION, request, fledgeAuctionConfig);
}, 'addComponentAuction');

// check that the bid has a width and height set
function validBidSize(adUnitCode, bid, {index = auctionManager.index} = {}) {
function validBidSize(adUnitCode, bid, { index = auctionManager.index } = {}) {
if ((bid.width || parseInt(bid.width, 10) === 0) && (bid.height || parseInt(bid.height, 10) === 0)) {
bid.width = parseInt(bid.width, 10);
bid.height = parseInt(bid.height, 10);
Expand All @@ -568,7 +569,7 @@ function validBidSize(adUnitCode, bid, {index = auctionManager.index} = {}) {
// if a banner impression has one valid size, we assign that size to any bid
// response that does not explicitly set width or height
if (parsedSizes.length === 1) {
const [ width, height ] = parsedSizes[0].split('x');
const [width, height] = parsedSizes[0].split('x');
bid.width = parseInt(width, 10);
bid.height = parseInt(height, 10);
return true;
Expand All @@ -578,7 +579,7 @@ function validBidSize(adUnitCode, bid, {index = auctionManager.index} = {}) {
}

// Validate the arguments sent to us by the adapter. If this returns false, the bid should be totally ignored.
export function isValid(adUnitCode, bid, {index = auctionManager.index} = {}) {
export function isValid(adUnitCode, bid, { index = auctionManager.index } = {}) {
function hasValidKeys() {
let bidKeys = Object.keys(bid);
return COMMON_BID_RESPONSE_KEYS.every(key => includes(bidKeys, key) && !includes([undefined, null], bid[key]));
Expand All @@ -603,15 +604,15 @@ export function isValid(adUnitCode, bid, {index = auctionManager.index} = {}) {
return false;
}

if (FEATURES.NATIVE && bid.mediaType === 'native' && !nativeBidIsValid(bid, {index})) {
if (FEATURES.NATIVE && bid.mediaType === 'native' && !nativeBidIsValid(bid, { index })) {
logError(errorMessage('Native bid missing some required properties.'));
return false;
}
if (FEATURES.VIDEO && bid.mediaType === 'video' && !isValidVideoBid(bid, {index})) {
if (FEATURES.VIDEO && bid.mediaType === 'video' && !isValidVideoBid(bid, { index })) {
logError(errorMessage(`Video bid does not have required vastUrl or renderer property`));
return false;
}
if (bid.mediaType === 'banner' && !validBidSize(adUnitCode, bid, {index})) {
if (bid.mediaType === 'banner' && !validBidSize(adUnitCode, bid, { index })) {
logError(errorMessage(`Banner bids require a width and height`));
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"BID_VIEWABLE": "bidViewable",
"STALE_RENDER": "staleRender",
"BILLABLE_EVENT": "billableEvent",
"BID_ACCEPTED": "bidAccepted"
"BID_ACCEPTED": "bidAccepted",
"ADD_COMPONENT_AUCTION": "addComponentAuction"
},
"AD_RENDER_FAILED_REASON": {
"PREVENT_WRITING_ON_MAIN_DOCUMENT": "preventWritingOnMainDocument",
Expand Down
Loading

0 comments on commit 10d9439

Please sign in to comment.