Skip to content

Commit

Permalink
minutemediaplus Bid Adapter - pass gpp, sua and bid data to server. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
saar120 authored Mar 21, 2023
1 parent e8cc73d commit 3ced406
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 43 deletions.
80 changes: 60 additions & 20 deletions modules/minutemediaplusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { _each, deepAccess, parseSizesInput, parseUrl, uniques, isFn } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import {_each, deepAccess, parseSizesInput, parseUrl, uniques, isFn} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getStorageManager} from '../src/storageManager.js';
import {config} from '../src/config.js';

const GVLID = 918;
const DEFAULT_SUB_DOMAIN = 'exchange';
Expand All @@ -22,11 +23,11 @@ export const SUPPORTED_ID_SYSTEMS = {
'tdid': 1,
'pubProvidedId': 1
};
const storage = getStorageManager({ gvlid: GVLID, bidderCode: BIDDER_CODE });
const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE});

function getTopWindowQueryParams() {
try {
const parsedUrl = parseUrl(window.top.document.URL, { decodeSearchAsString: true });
const parsedUrl = parseUrl(window.top.document.URL, {decodeSearchAsString: true});
return parsedUrl.search;
} catch (e) {
return '';
Expand Down Expand Up @@ -54,9 +55,22 @@ function isBidRequestValid(bid) {
return !!(extractCID(params) && extractPID(params));
}

function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
const { params, bidId, userId, adUnitCode, schain, mediaTypes } = bid;
let { bidFloor, ext } = params;
function buildRequest(bid, topWindowUrl, sizes, bidderRequest, bidderTimeout) {
const {
params,
bidId,
userId,
adUnitCode,
schain,
mediaTypes,
auctionId,
transactionId,
bidderRequestId,
bidRequestsCount,
bidderRequestsCount,
bidderWinsCount
} = bid;
let {bidFloor, ext} = params;
const hashUrl = hashCode(topWindowUrl);
const uniqueDealId = getUniqueDealId(hashUrl);
const cId = extractCID(params);
Expand Down Expand Up @@ -90,11 +104,24 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
prebidVersion: '$prebid.version$',
res: `${screen.width}x${screen.height}`,
schain: schain,
mediaTypes: mediaTypes
mediaTypes: mediaTypes,
auctionId: auctionId,
transactionId: transactionId,
bidderRequestId: bidderRequestId,
bidRequestsCount: bidRequestsCount,
bidderRequestsCount: bidderRequestsCount,
bidderWinsCount: bidderWinsCount,
bidderTimeout: bidderTimeout
};

appendUserIdsToRequestPayload(data, userId);

const sua = deepAccess(bidderRequest, 'ortb2.device.sua');

if (sua) {
data.sua = sua;
}

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString) {
data.gdprConsent = bidderRequest.gdprConsent.consentString;
Expand All @@ -107,6 +134,14 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) {
data.usPrivacy = bidderRequest.uspConsent;
}

if (bidderRequest.gppConsent) {
data.gppString = bidderRequest.gppConsent.gppString;
data.gppSid = bidderRequest.gppConsent.applicableSections;
} else if (bidderRequest.ortb2?.regs?.gpp) {
data.gppString = bidderRequest.ortb2.regs.gpp;
data.gppSid = bidderRequest.ortb2.regs.gpp_sid;
}

const dto = {
method: 'POST',
url: `${createDomain(subDomain)}/prebid/multi/${cId}`,
Expand Down Expand Up @@ -148,10 +183,11 @@ function appendUserIdsToRequestPayload(payloadRef, userIds) {

function buildRequests(validBidRequests, bidderRequest) {
const topWindowUrl = bidderRequest.refererInfo.page || bidderRequest.refererInfo.topmostLocation;
const bidderTimeout = config.getConfig('bidderTimeout');
const requests = [];
validBidRequests.forEach(validBidRequest => {
const sizes = parseSizesInput(validBidRequest.sizes);
const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest);
const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest, bidderTimeout);
requests.push(request);
});
return requests;
Expand All @@ -161,14 +197,14 @@ function interpretResponse(serverResponse, request) {
if (!serverResponse || !serverResponse.body) {
return [];
}
const { bidId } = request.data;
const { results } = serverResponse.body;
const {bidId} = request.data;
const {results} = serverResponse.body;

let output = [];

try {
results.forEach(result => {
const { creativeId, ad, price, exp, width, height, currency, advertiserDomains, mediaType = BANNER } = result;
const {creativeId, ad, price, exp, width, height, currency, advertiserDomains, mediaType = BANNER} = result;
if (!ad || !price) {
return;
}
Expand Down Expand Up @@ -207,8 +243,8 @@ function interpretResponse(serverResponse, request) {

function getUserSyncs(syncOptions, responses, gdprConsent = {}, uspConsent = '') {
let syncs = [];
const { iframeEnabled, pixelEnabled } = syncOptions;
const { gdprApplies, consentString = '' } = gdprConsent;
const {iframeEnabled, pixelEnabled} = syncOptions;
const {gdprApplies, consentString = ''} = gdprConsent;

const cidArr = responses.filter(resp => deepAccess(resp, 'body.cid')).map(resp => resp.body.cid).filter(uniques);
const params = `?cid=${encodeURIComponent(cidArr.join(','))}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${encodeURIComponent(consentString || '')}&us_privacy=${encodeURIComponent(uspConsent || '')}`
Expand All @@ -232,7 +268,9 @@ export function hashCode(s, prefix = '_') {
let h = 0
let i = 0;
if (l > 0) {
while (i < l) { h = (h << 5) - h + s.charCodeAt(i++) | 0; }
while (i < l) {
h = (h << 5) - h + s.charCodeAt(i++) | 0;
}
}
return prefix + h;
}
Expand All @@ -256,17 +294,19 @@ export function getUniqueDealId(key, expiry = UNIQUE_DEAL_ID_EXPIRY) {
export function getStorageItem(key) {
try {
return tryParseJSON(storage.getDataFromLocalStorage(key));
} catch (e) { }
} catch (e) {
}

return null;
}

export function setStorageItem(key, value, timestamp) {
try {
const created = timestamp || Date.now();
const data = JSON.stringify({ value, created });
const data = JSON.stringify({value, created});
storage.setDataInLocalStorage(key, data);
} catch (e) { }
} catch (e) {
}
}

export function tryParseJSON(value) {
Expand Down
Loading

0 comments on commit 3ced406

Please sign in to comment.