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

GumGum: sends maxw and maxh query parameters for slot requests #7232

Merged
merged 8 commits into from
Aug 19, 2021
86 changes: 59 additions & 27 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DELAY_REQUEST_TIME = 1800000; // setting to 30 mins

let invalidRequestIds = {};
let browserParams = {};
let pageViewId = null
let pageViewId = null;

// TODO: potential 0 values for browserParams sent to ad server
function _getBrowserParams(topWindowUrl) {
Expand All @@ -28,12 +28,12 @@ function _getBrowserParams(topWindowUrl) {
let topUrl
let ggad
let ns
function getNetworkSpeed () {
function getNetworkSpeed() {
const connection = window.navigator && (window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection)
const Mbps = connection && (connection.downlink || connection.bandwidth)
return Mbps ? Math.round(Mbps * 1024) : null
}
function getOgURL () {
function getOgURL() {
let ogURL = ''
const ogURLSelector = "meta[property='og:url']"
const head = document && document.getElementsByTagName('head')[0]
Expand Down Expand Up @@ -122,7 +122,7 @@ function _serializeSupplyChainObj(schainObj) {
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
function isBidRequestValid (bid) {
function isBidRequestValid(bid) {
const {
params,
adUnitCode
Expand Down Expand Up @@ -163,7 +163,7 @@ function isBidRequestValid (bid) {
* @param {Object} attributes
* @returns {Object}
*/
function _getVidParams (attributes) {
function _getVidParams(attributes) {
const {
minduration: mind,
maxduration: maxd,
Expand Down Expand Up @@ -200,7 +200,7 @@ function _getVidParams (attributes) {
* @param {Object} bid
* @returns {Number} floor
*/
function _getFloor (mediaTypes, staticBidFloor, bid) {
function _getFloor(mediaTypes, staticBidFloor, bid) {
const curMediaType = Object.keys(mediaTypes)[0] || 'banner';
const bidFloor = { floor: 0, currency: 'USD' };

Expand All @@ -222,7 +222,29 @@ function _getFloor (mediaTypes, staticBidFloor, bid) {
return bidFloor;
}

function getEids (userId) {
/**
* loops through bannerSizes array to get greatest slot dimensions
* @param {number[][]} sizes
* @returns {number[]}
*/
function getGreatestDimensions(sizes) {
let maxw = 0;
let maxh = 0;
let greatestVal = 0;
sizes.forEach(bannerSize => {
let [width, height] = bannerSize;
let greaterSide = width > height ? width : height;
if ((greaterSide > greatestVal) || (greaterSide === greatestVal && width >= maxw && height >= maxh)) {
gwhigs marked this conversation as resolved.
Show resolved Hide resolved
greatestVal = greaterSide;
maxw = width;
maxh = height;
}
});

return [maxw, maxh];
}

function getEids(userId) {
const idProperties = [
'uid',
'eid',
Expand Down Expand Up @@ -251,7 +273,7 @@ function getEids (userId) {
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
function buildRequests (validBidRequests, bidderRequest) {
function buildRequests(validBidRequests, bidderRequest) {
const bids = [];
const gdprConsent = bidderRequest && bidderRequest.gdprConsent;
const uspConsent = bidderRequest && bidderRequest.uspConsent;
Expand Down Expand Up @@ -311,6 +333,9 @@ function buildRequests (validBidRequests, bidderRequest) {
data.pi = 2; // inscreen
// override pi if the following is found
if (params.slot) {
const [maxw, maxh] = getGreatestDimensions(sizes);
data.maxw = maxw;
data.maxh = maxh;
data.si = parseInt(params.slot, 10);
data.pi = 3;
data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, '');
Expand Down Expand Up @@ -353,7 +378,7 @@ function buildRequests (validBidRequests, bidderRequest) {
return bids;
}

function handleLegacyParams (params, sizes) {
function handleLegacyParams(params, sizes) {
const data = {};
if (params.inScreenPubID) {
data.pubId = params.inScreenPubID;
Expand All @@ -364,6 +389,9 @@ function handleLegacyParams (params, sizes) {
data.pi = 2;
}
if (params.inSlot) {
const [maxw, maxh] = getGreatestDimensions(sizes);
data.maxw = maxw;
data.maxh = maxh;
data.si = parseInt(params.inSlot, 10);
data.pi = 3;
data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, '');
Expand Down Expand Up @@ -393,12 +421,12 @@ function handleLegacyParams (params, sizes) {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
function interpretResponse (serverResponse, bidRequest) {
function interpretResponse(serverResponse, bidRequest) {
const bidResponses = []
const serverResponseBody = serverResponse.body

if (!serverResponseBody || serverResponseBody.err) {
const data = bidRequest.data || {}
const data = bidRequest.data || {};
const id = data.si || data.ni || data.t || data.pubId;
const delayTime = serverResponseBody ? serverResponseBody.err.drt : DELAY_REQUEST_TIME;
invalidRequestIds[id] = { productId: data.pi, timestamp: new Date().getTime() };
Expand Down Expand Up @@ -432,7 +460,9 @@ function interpretResponse (serverResponse, bidRequest) {
markup,
cur,
width: responseWidth,
height: responseHeight
height: responseHeight,
maxw,
maxh
},
cw: wrapper,
pag: {
Expand All @@ -443,24 +473,26 @@ function interpretResponse (serverResponse, bidRequest) {
adomain: advertiserDomains,
mediaType: type
}
} = Object.assign(defaultResponse, serverResponseBody)
let data = bidRequest.data || {}
let product = data.pi
let mediaType = (product === 6 || product === 7) ? VIDEO : BANNER
let isTestUnit = (product === 3 && data.si === 9)
// use response sizes if available
let sizes = responseWidth && responseHeight ? [`${responseWidth}x${responseHeight}`] : utils.parseSizesInput(bidRequest.sizes)
let [width, height] = sizes[0].split('x')
} = Object.assign(defaultResponse, serverResponseBody);
let data = bidRequest.data || {};
let product = data.pi;
let mediaType = (product === 6 || product === 7) ? VIDEO : BANNER;
let isTestUnit = (product === 3 && data.si === 9);
let metaData = {
advertiserDomains: advertiserDomains || [],
mediaType: type || mediaType
};
let sizes = utils.parseSizesInput(bidRequest.sizes);

if (maxw && maxh) {
sizes = [`${maxw}x${maxh}`];
} else if (product === 5 && includes(sizes, '1x1')) {
sizes = ['1x1'];
} else if (product === 2 && includes(sizes, '1x1')) {
sizes = responseWidth && responseHeight ? [`${responseWidth}x${responseHeight}`] : utils.parseSizesInput(bidRequest.sizes)
}

// return 1x1 when breakout expected
if ((product === 2 || product === 5) && includes(sizes, '1x1')) {
width = '1'
height = '1'
}
let [width, height] = sizes[0].split('x');

if (jcsi) {
serverResponseBody.jcsi = JCSI
Expand All @@ -474,7 +506,7 @@ function interpretResponse (serverResponse, bidRequest) {
// dealId: DEAL_ID,
// referrer: REFERER,
ad: wrapper ? getWrapperCode(wrapper, Object.assign({}, serverResponseBody, { bidRequest })) : markup,
...(mediaType === VIDEO && {ad: markup, vastXml: markup}),
...(mediaType === VIDEO && { ad: markup, vastXml: markup }),
mediaType,
cpm: isTestUnit ? 0.1 : cpm,
creativeId,
Expand All @@ -497,7 +529,7 @@ function interpretResponse (serverResponse, bidRequest) {
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
function getUserSyncs (syncOptions, serverResponses) {
function getUserSyncs(syncOptions, serverResponses) {
const responses = serverResponses.map((response) => {
return (response.body && response.body.pxs && response.body.pxs.scr) || []
})
Expand Down
Loading