Skip to content

Commit

Permalink
Merge branch 'master' into id-7317
Browse files Browse the repository at this point in the history
  • Loading branch information
abazylewicz-id5 authored Jan 12, 2024
2 parents 8d8c872 + 759d5ac commit ab318ce
Show file tree
Hide file tree
Showing 36 changed files with 2,858 additions and 233 deletions.
91 changes: 91 additions & 0 deletions integrationExamples/gpt/contxtfulRtdProvider_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<html>

<head>
<script src="http://localhost:9999/build/dev/prebid.js" async></script>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script async>
const FAILSAFE_TIMEOUT = 8000;
const PREBID_TIMEOUT = 5000;

const bidders = [
{
bidder: 'appnexus',
params: {
placementId: 13144370
}
}
];

var adUnits = [
{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]],
}
},
bids: bidders,
}
];


var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});

pbjs.que.push(function () {
pbjs.setConfig({
debug: true,
realTimeData: {
auctionDelay: 100,
dataProviders: [
{
name: "contxtful",
waitForIt: true,
params: {
version: "Contact contact@contxtful.com for the API version",
customer: "Contact contact@contxtful.com for the customer ID"
}
}
]
}
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: PREBID_TIMEOUT
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function () {
sendAdserverRequest();
}, FAILSAFE_TIMEOUT);

</script>
</head>

<body>
<h2>Contxtful RTD Provider</h2>
<div id='div-gpt-ad-1460505748561-0'></div>
</div>
</body>

</html>
103 changes: 72 additions & 31 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ const NATIVE_INDEX = NATIVE_MODEL.reduce((acc, val, idx) => {
return acc;
}, {});

const MULTI_FORMAT_SUFFIX = '__mf';
const MULTI_FORMAT_SUFFIX_BANNER = 'b' + MULTI_FORMAT_SUFFIX;
const MULTI_FORMAT_SUFFIX_VIDEO = 'v' + MULTI_FORMAT_SUFFIX;
const MULTI_FORMAT_SUFFIX_NATIVE = 'n' + MULTI_FORMAT_SUFFIX;

/**
* Adapter for requesting bids from AdKernel white-label display platform
*/
Expand Down Expand Up @@ -173,6 +178,9 @@ export const spec = {
ttl: 360,
netRevenue: true
};
if (prBid.requestId.endsWith(MULTI_FORMAT_SUFFIX)) {
prBid.requestId = stripMultiformatSuffix(prBid.requestId);
}
if ('banner' in imp) {
prBid.mediaType = BANNER;
prBid.width = rtbBid.w;
Expand Down Expand Up @@ -239,13 +247,13 @@ registerBidder(spec);
function groupImpressionsByHostZone(bidRequests, refererInfo) {
let secure = (refererInfo && refererInfo.page?.indexOf('https:') === 0);
return Object.values(
bidRequests.map(bidRequest => buildImp(bidRequest, secure))
bidRequests.map(bidRequest => buildImps(bidRequest, secure))
.reduce((acc, curr, index) => {
let bidRequest = bidRequests[index];
let {zoneId, host} = bidRequest.params;
let key = `${host}_${zoneId}`;
acc[key] = acc[key] || {host: host, zoneId: zoneId, imps: []};
acc[key].imps.push(curr);
acc[key].imps.push(...curr);
return acc;
}, {})
);
Expand All @@ -264,61 +272,90 @@ function getBidFloor(bid, mediaType, sizes) {
}

/**
* Builds rtb imp object for single adunit
* Builds rtb imp object(s) for single adunit
* @param bidRequest {BidRequest}
* @param secure {boolean}
*/
function buildImp(bidRequest, secure) {
const imp = {
function buildImps(bidRequest, secure) {
let imp = {
'id': bidRequest.bidId,
'tagid': bidRequest.adUnitCode
};
var mediaType;
if (secure) {
imp.secure = 1;
}
var sizes = [];

if (bidRequest.mediaTypes?.banner) {
let mediaTypes = bidRequest.mediaTypes;
let isMultiformat = (~~!!mediaTypes?.banner + ~~!!mediaTypes?.video + ~~!!mediaTypes?.native) > 1;
let result = [];
let typedImp;

if (mediaTypes?.banner) {
if (isMultiformat) {
typedImp = {...imp};
typedImp.id = imp.id + MULTI_FORMAT_SUFFIX_BANNER;
} else {
typedImp = imp;
}
sizes = getAdUnitSizes(bidRequest);
let pbBanner = bidRequest.mediaTypes.banner;
imp.banner = {
let pbBanner = mediaTypes.banner;
typedImp.banner = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, BANNER_FPD),
...getDefinedParamsOrEmpty(pbBanner, BANNER_PARAMS),
format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)),
topframe: 0
};
mediaType = BANNER;
} else if (bidRequest.mediaTypes?.video) {
let pbVideo = bidRequest.mediaTypes.video;
imp.video = {
initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : BANNER);
result.push(typedImp);
}

if (mediaTypes?.video) {
if (isMultiformat) {
typedImp = {...imp};
typedImp.id = typedImp.id + MULTI_FORMAT_SUFFIX_VIDEO;
} else {
typedImp = imp;
}
let pbVideo = mediaTypes.video;
typedImp.video = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, VIDEO_FPD),
...getDefinedParamsOrEmpty(pbVideo, VIDEO_PARAMS)
};
if (pbVideo.playerSize) {
sizes = pbVideo.playerSize[0];
imp.video = Object.assign(imp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {});
typedImp.video = Object.assign(typedImp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {});
} else if (pbVideo.w && pbVideo.h) {
imp.video.w = pbVideo.w;
imp.video.h = pbVideo.h;
typedImp.video.w = pbVideo.w;
typedImp.video.h = pbVideo.h;
}
mediaType = VIDEO;
} else if (bidRequest.mediaTypes?.native) {
let nativeRequest = buildNativeRequest(bidRequest.mediaTypes.native);
imp.native = {
initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : VIDEO);
result.push(typedImp);
}

if (mediaTypes?.native) {
if (isMultiformat) {
typedImp = {...imp};
typedImp.id = typedImp.id + MULTI_FORMAT_SUFFIX_NATIVE;
} else {
typedImp = imp;
}
let nativeRequest = buildNativeRequest(mediaTypes.native);
typedImp.native = {
...getDefinedParamsOrEmpty(bidRequest.ortb2Imp, NATIVE_FPD),
ver: '1.1',
request: JSON.stringify(nativeRequest)
};
mediaType = NATIVE;
} else {
throw new Error('Unsupported bid received');
}
let floor = getBidFloor(bidRequest, mediaType, sizes);
if (floor) {
imp.bidfloor = floor;
initImpBidfloor(typedImp, bidRequest, sizes, isMultiformat ? '*' : NATIVE);
result.push(typedImp);
}
if (secure) {
imp.secure = 1;
return result;
}

function initImpBidfloor(imp, bid, sizes, mediaType) {
let bidfloor = getBidFloor(bid, mediaType, sizes);
if (bidfloor) {
imp.bidfloor = bidfloor;
}
return imp;
}

function getDefinedParamsOrEmpty(object, params) {
Expand Down Expand Up @@ -643,3 +680,7 @@ function buildNativeAd(nativeResp) {
});
return cleanObj(nativeAd);
}

function stripMultiformatSuffix(impid) {
return impid.substr(0, impid.length - MULTI_FORMAT_SUFFIX.length - 1);
}
Loading

0 comments on commit ab318ce

Please sign in to comment.