Skip to content

Commit

Permalink
Ogury Bid Adapter : integrate ORTB Converter Library (#12661)
Browse files Browse the repository at this point in the history
* use ortb converter lib on Ogury adapter

* override site.page with current location when publisher overrides ortb2 object with wrong values
  • Loading branch information
antoinezaz authored Jan 24, 2025
1 parent c867a9b commit 1e1381a
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 697 deletions.
205 changes: 65 additions & 140 deletions modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,80 @@
'use strict';

import {BANNER} from '../src/mediaTypes.js';
import {getWindowSelf, getWindowTop, isFn, logWarn, deepAccess, isPlainObject} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {ajax} from '../src/ajax.js';
import {getAdUnitSizes} from '../libraries/sizeUtils/sizeUtils.js';
import { BANNER } from '../src/mediaTypes.js';
import { getWindowSelf, getWindowTop, isFn, deepAccess, isPlainObject, deepSetValue, mergeDeep } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { ajax } from '../src/ajax.js';
import { getAdUnitSizes } from '../libraries/sizeUtils/sizeUtils.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';

const BIDDER_CODE = 'ogury';
const GVLID = 31;
const DEFAULT_TIMEOUT = 1000;
const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io';
const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io';
const ADAPTER_VERSION = '1.7.0';
const ADAPTER_VERSION = '2.0.0';

export const converter = ortbConverter({
context: {
netRevenue: true,
ttl: 60,
mediaType: 'banner'
},

request(buildRequest, imps, bidderRequest, context) {
const req = buildRequest(imps, bidderRequest, context);
req.tmax = DEFAULT_TIMEOUT;
deepSetValue(req, 'device.pxratio', window.devicePixelRatio);
deepSetValue(req, 'site.page', getWindowContext().location.href);

req.ext = mergeDeep({}, req.ext, {
adapterversion: ADAPTER_VERSION,
prebidversion: '$prebid.version$'
});

function getClientWidth() {
const documentElementClientWidth = window.top.document.documentElement.clientWidth
? window.top.document.documentElement.clientWidth
: 0
const innerWidth = window.top.innerWidth ? window.top.innerWidth : 0
const outerWidth = window.top.outerWidth ? window.top.outerWidth : 0
const screenWidth = window.top.screen.width ? window.top.screen.width : 0
const bidWithAssetKey = bidderRequest.bids.find(bid => Boolean(deepAccess(bid, 'params.assetKey', false)));
if (bidWithAssetKey) deepSetValue(req, 'site.id', bidWithAssetKey.params.assetKey);

return documentElementClientWidth || innerWidth || outerWidth || screenWidth
}
const bidWithUserIds = bidderRequest.bids.find(bid => Boolean(bid.userId));
if (bidWithUserIds) deepSetValue(req, 'user.ext.uids', bidWithUserIds.userId);

function getClientHeight() {
const documentElementClientHeight = window.top.document.documentElement.clientHeight
? window.top.document.documentElement.clientHeight
: 0
const innerHeight = window.top.innerHeight ? window.top.innerHeight : 0
const outerHeight = window.top.outerHeight ? window.top.outerHeight : 0
const screenHeight = window.top.screen.height ? window.top.screen.height : 0
return req;
},

return documentElementClientHeight || innerHeight || outerHeight || screenHeight
}
imp(buildImp, bidRequest, context) {
const imp = buildImp(bidRequest, context);
const timeSpentOnPage = document.timeline && document.timeline.currentTime ? document.timeline.currentTime : 0
const gpid = bidRequest.adUnitCode;
imp.tagid = bidRequest.adUnitCode;
imp.ext = mergeDeep({}, bidRequest.params, { timeSpentOnPage, gpid }, imp.ext);

const bidfloor = getFloor(bidRequest);

if (!bidfloor) {
delete imp.bidfloor;
} else {
imp.bidfloor = bidfloor;
}

return imp;
},

bidResponse(buildBidResponse, bid, context) {
const bidResponse = buildBidResponse(bid, context);
bidResponse.currency = 'USD';
return bidResponse;
}
});

function isBidRequestValid(bid) {
const adUnitSizes = getAdUnitSizes(bid);

const isValidSizes = Boolean(adUnitSizes) && adUnitSizes.length > 0;
const isValidAdUnitId = !!bid.params.adUnitId;
const isValidAssetKey = !!bid.params.assetKey;
const isValidSize = (Boolean(adUnitSizes) && adUnitSizes.length > 0);
const hasAssetKeyAndAdUnitId = !!deepAccess(bid, 'params.adUnitId') && !!deepAccess(bid, 'params.assetKey');
const hasPublisherIdAndAdUnitCode = !!deepAccess(bid, 'ortb2.site.publisher.id') && !!bid.adUnitCode;

return (isValidSizes && isValidAdUnitId && isValidAssetKey);
return isValidSize && (hasAssetKeyAndAdUnitId || hasPublisherIdAndAdUnitCode);
}

function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
Expand Down Expand Up @@ -80,126 +111,19 @@ function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gpp
return [];
}

function buildRequests(validBidRequests, bidderRequest) {
const openRtbBidRequestBanner = {
id: bidderRequest.bidderRequestId,
tmax: Math.min(DEFAULT_TIMEOUT, bidderRequest.timeout),
at: 1,
regs: {
ext: {
gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
},
},
site: {
domain: location.hostname,
page: location.href
},
user: {
ext: {
consent: ''
}
},
imp: [],
ext: {
adapterversion: ADAPTER_VERSION,
prebidversion: '$prebid.version$'
},
device: {
w: getClientWidth(),
h: getClientHeight(),
pxratio: window.devicePixelRatio
}
};

if (bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) {
openRtbBidRequestBanner.user.ext.consent = bidderRequest.gdprConsent.consentString
}
if (bidderRequest.gppConsent && bidderRequest.gppConsent.gppString) {
openRtbBidRequestBanner.regs.ext.gpp = bidderRequest.gppConsent.gppString
}
if (bidderRequest.gppConsent && bidderRequest.gppConsent.applicableSections) {
openRtbBidRequestBanner.regs.ext.gpp_sid = bidderRequest.gppConsent.applicableSections
}

validBidRequests.forEach((bidRequest) => {
const sizes = getAdUnitSizes(bidRequest)
.map(size => ({ w: size[0], h: size[1] }));

if (bidRequest.mediaTypes &&
bidRequest.mediaTypes.hasOwnProperty('banner')) {
openRtbBidRequestBanner.site.id = bidRequest.params.assetKey;
const floor = getFloor(bidRequest);

if (bidRequest.userId) {
openRtbBidRequestBanner.user.ext.uids = bidRequest.userId
}
if (bidRequest.userIdAsEids) {
openRtbBidRequestBanner.user.ext.eids = bidRequest.userIdAsEids
}

const gpid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid');

openRtbBidRequestBanner.imp.push({
id: bidRequest.bidId,
tagid: bidRequest.params.adUnitId,
...(floor && {bidfloor: floor}),
banner: {
format: sizes
},
ext: {
...bidRequest.params,
...(gpid && {gpid}),
timeSpentOnPage: document.timeline && document.timeline.currentTime ? document.timeline.currentTime : 0
}
});
}
});
function buildRequests(bidRequests, bidderRequest) {
const data = converter.toORTB({bidRequests, bidderRequest});

return {
method: 'POST',
url: BID_HOST,
data: openRtbBidRequestBanner,
data,
options: {contentType: 'application/json'},
};
}

function interpretResponse(openRtbBidResponse) {
if (!openRtbBidResponse ||
!openRtbBidResponse.body ||
typeof openRtbBidResponse.body != 'object' ||
Object.keys(openRtbBidResponse.body).length === 0) {
logWarn('no response or body is malformed');
return [];
}

const bidResponses = [];

openRtbBidResponse.body.seatbid.forEach((seatbid) => {
seatbid.bid.forEach((bid) => {
let bidResponse = {
requestId: bid.impid,
cpm: bid.price,
currency: 'USD',
width: bid.w,
height: bid.h,
creativeId: bid.id,
netRevenue: true,
ttl: 60,
ext: bid.ext,
meta: {
advertiserDomains: bid.adomain
},
nurl: bid.nurl,
adapterVersion: ADAPTER_VERSION,
prebidVersion: '$prebid.version$'
};

bidResponse.ad = bid.adm;

bidResponses.push(bidResponse);
});
});
return bidResponses;
function interpretResponse(response, request) {
return converter.fromORTB({response: response.body, request: request.data}).bids;
}

function getFloor(bid) {
Expand All @@ -211,6 +135,7 @@ function getFloor(bid) {
mediaType: 'banner',
size: '*'
});

return (isPlainObject(floorResult) && floorResult.currency === 'USD') ? floorResult.floor : 0;
}

Expand Down
Loading

0 comments on commit 1e1381a

Please sign in to comment.