Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickloughrey authored Feb 13, 2023
2 parents b564323 + 5ba4e65 commit 2ba7832
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 46 deletions.
5 changes: 2 additions & 3 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,8 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
}
};
};
request.user = {
ext: bidderRequest.userExt
};
request.user = bidderRequest.ortb2?.user || {};
request.site = bidderRequest.ortb2?.site || {};
if (bidderRequest && bidderRequest.ceh) {
request.user.ceh = bidderRequest.ceh;
}
Expand Down
74 changes: 54 additions & 20 deletions modules/kueezRtbBidAdapter.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 = 1165;
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,7 +104,14 @@ 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);
Expand All @@ -107,6 +128,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 +177,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 +191,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 +237,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 +262,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 +288,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
25 changes: 24 additions & 1 deletion test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,18 @@ describe('The Criteo bidding adapter', function () {
it('should properly build a request with first party data', function () {
const siteData = {
keywords: ['power tools'],
content: {
data: [{
name: 'some_provider',
ext: {
segtax: 3
},
segment: [
{ 'id': '1001' },
{ 'id': '1002' }
]
}]
},
ext: {
data: {
pageType: 'article'
Expand All @@ -1164,6 +1176,16 @@ describe('The Criteo bidding adapter', function () {
};
const userData = {
gender: 'M',
data: [{
name: 'some_provider',
ext: {
segtax: 3
},
segment: [
{ 'id': '1001' },
{ 'id': '1002' }
]
}],
ext: {
data: {
registered: true
Expand Down Expand Up @@ -1203,7 +1225,8 @@ describe('The Criteo bidding adapter', function () {

const request = spec.buildRequests(bidRequests, { ...bidderRequest, ortb2 });
expect(request.data.publisher.ext).to.deep.equal({ data: { pageType: 'article' } });
expect(request.data.user.ext).to.deep.equal({ data: { registered: true } });
expect(request.data.user).to.deep.equal(userData);
expect(request.data.site).to.deep.equal(siteData);
expect(request.data.slots[0].ext).to.deep.equal({
bidfloor: 0.75,
data: {
Expand Down
Loading

0 comments on commit 2ba7832

Please sign in to comment.