Skip to content

Commit

Permalink
debug(oxxionRtdProvider): onAuctionInit()
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyguyot-msq committed Jan 25, 2023
1 parent 7b25737 commit d0894e3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 52 additions & 1 deletion modules/oxxionRtdProvider.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { submodule } from '../src/hook.js'
import { deepAccess, logInfo } from '../src/utils.js'
import MD5 from 'crypto-js/md5.js';
// import { ajax } from '../src/ajax.js';

const oxxionRtdSearchFor = [ 'adUnitCode', 'auctionId', 'bidder', 'bidderCode', 'bidId', 'cpm', 'creativeId', 'currency', 'width', 'height', 'mediaType', 'netRevenue', 'originalCpm', 'originalCurrency', 'requestId', 'size', 'source', 'status', 'timeToRespond', 'transactionId', 'ttl', 'sizes', 'mediaTypes', 'src', 'userId', 'labelAny', 'adId' ];
const LOG_PREFIX = 'oxxionRtdProvider submodule: ';

const CHECK_INTEREST_URL = 'http://wwww.interest.com/api/';
const allAdUnits = [];

/** @type {RtdSubmodule} */
export const oxxionSubmodule = {
name: 'oxxionRtd',
init: init,
onAuctionInitEvent: onAuctionInit,
onAuctionEndEvent: onAuctionEnd,
getBidRequestData: getAdUnits,
};

function init(config, userConsent) {
logInfo(LOG_PREFIX, 'init()', config, userConsent);
if (!config.params || !config.params.domain || !config.params.contexts || !Array.isArray(config.params.contexts) || config.params.contexts.length == 0) {
return false
}
Expand All @@ -32,6 +36,35 @@ function getAdUnits(reqBidsConfigObj, callback, config, userConsent) {
}
}

function onAuctionInit (auctionDetails, config, userConsent) {
logInfo(LOG_PREFIX, 'onAuctionInit()', {
auctionDetails,
config,
userConsent
});
const { keys } = Object;
const { stringify } = JSON;
const gdpr = userConsent.gdpr.consentString;
let index = 0;
const requests = auctionDetails.adUnits.flatMap(({ bids = [], mediaTypes = [], code = '' }) => {
return bids.flatMap(({ bidder, params = {} }) => {
return keys(mediaTypes).map((mediaTypeKey) => ({
id: index++,
adUnit: code,
bidder,
mediaType: mediaTypeKey,
params: MD5(stringify(params)).toString(),
sizes: mediaTypes[mediaTypeKey].sizes || []
}));
});
});
const payload = {
gdpr,
requests
};
logInfo(LOG_PREFIX, 'onAuctionInit() payload', payload);
}

function insertVideoTracking(bidResponse, config, maxCpm) {
if (bidResponse.mediaType === 'video') {
const trackingUrl = getImpUrl(config, bidResponse, maxCpm);
Expand Down Expand Up @@ -116,4 +149,22 @@ function onAuctionEnd(auctionDetails, config, userConsent) {
});
}

function getPromisifiedAjax (url, data = {}, options = {}) {
return new Promise((resolve, reject) => {
const callbacks = {
success(responseText, { response }) {
resolve(JSON.parse(response));
},
error(error) {
reject(error);
}
};
ajax(url, callbacks, data, options);
})
}

function getRandomNumber (max) {
return Math.round(Math.random() * max);
}

submodule('realTimeData', oxxionSubmodule);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"header bidding",
"prebid"
],
"globalVarName": "pbjs",
"globalVarName": "msq_pbjs",
"author": "the prebid.js contributors",
"license": "Apache-2.0",
"engines": {
Expand Down

0 comments on commit d0894e3

Please sign in to comment.