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
alexartwww authored Jan 13, 2022
2 parents 8f8a9e8 + 9783e9f commit 1c6cfdf
Show file tree
Hide file tree
Showing 22 changed files with 1,253 additions and 86 deletions.
44 changes: 11 additions & 33 deletions integrationExamples/gpt/amp/creative.html
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
<!-- This script tag should be returned by your ad server -->

<script src="https://cdn.jsdelivr.net/npm/prebid-universal-creative@latest/dist/creative.js"></script>
<script>
// This is the `renderAd` function from Prebid.js moved within the creative iframe
var renderAd = function (ev) {
var key = ev.message ? "message" : "data";
var data = {};
try {
data = JSON.parse(ev[key]);
} catch (e) {
// Do nothing. No ad found.
}
if (data.ad || data.adUrl) {
if (data.ad) {
document.write(data.ad);
document.close();
} else if (data.adUrl) {
document.write('<IFRAME SRC="' + data.adUrl + '" WIDTH="'+ data.width +'" HEIGHT="'+ data.height +'" FRAMEBORDER="0" SCROLLING="no" MARGINHEIGHT="0" MARGINWIDTH="0" TOPMARGIN="0" LEFTMARGIN="0" ALLOWTRANSPARENCY="true"></IFRAME>');
document.close();
}
}
};
var ucTagData = {};
ucTagData.adServerDomain = "";
ucTagData.pubUrl = "%%PATTERN:url%%";
ucTagData.targetingMap = "%%PATTERN:TARGETINGMAP%%";
ucTagData.hbPb = "%%PATTERN:hb_pb%%";

var requestAdFromPrebid = function () {
var message = JSON.stringify({
message: 'Prebid creative requested: %%PATTERN:hb_adid%%',
adId: '%%PATTERN:hb_adid%%'
});
window.parent.postMessage(message, '*');
};

var listenAdFromPrebid = function () {
window.addEventListener("message", renderAd, false);
};

listenAdFromPrebid();
requestAdFromPrebid();
try {
ucTag.renderAd(document, ucTagData);
} catch (e) {
console.log(e);
}
</script>
37 changes: 27 additions & 10 deletions modules/adbookpspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function impBidsToPrebidBids(
}

const impToPrebidBid =
(bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid) => {
(bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid, bidIndex) => {
try {
const bidRequest = findBidRequest(bidderRequestBody, bid);

Expand All @@ -377,7 +377,7 @@ const impToPrebidBid =
let prebidBid = {
ad: bid.adm,
adId: bid.adid,
adserverTargeting: targetingMap[bid.impid],
adserverTargeting: targetingMap[bidIndex],
adUnitCode: bidRequest.tagid,
bidderRequestId: bidderRequestBody.id,
bidId: bid.id,
Expand Down Expand Up @@ -408,6 +408,9 @@ const impToPrebidBid =
};
}

if (deepAccess(bid, 'ext.pa_win') === true) {
prebidBid.auctionWinner = true;
}
return prebidBid;
} catch (error) {
logError(`${BIDDER_CODE}: Error while building bid`, error);
Expand All @@ -429,29 +432,43 @@ function buildTargetingMap(bids) {
const values = impIds.reduce((result, id) => {
result[id] = {
lineItemIds: [],
orderIds: [],
dealIds: [],
adIds: [],
adAndOrderIndexes: []
};

return result;
}, {});

bids.forEach((bid) => {
values[bid.impid].lineItemIds.push(bid.ext.liid);
values[bid.impid].dealIds.push(bid.dealid);
values[bid.impid].adIds.push(bid.adid);
bids.forEach((bid, bidIndex) => {
let impId = bid.impid;
values[impId].lineItemIds.push(bid.ext.liid);
values[impId].dealIds.push(bid.dealid);
values[impId].adIds.push(bid.adid);

if (deepAccess(bid, 'ext.ordid')) {
values[impId].orderIds.push(bid.ext.ordid);
bid.ext.ordid.split(TARGETING_VALUE_SEPARATOR).forEach((ordid, ordIndex) => {
let adIdIndex = values[impId].adIds.indexOf(bid.adid);
values[impId].adAndOrderIndexes.push(adIdIndex + '_' + ordIndex)
})
}
});

const targetingMap = {};

for (const id of impIds) {
targetingMap[id] = {
bids.forEach((bid, bidIndex) => {
let id = bid.impid;

targetingMap[bidIndex] = {
hb_liid_adbookpsp: values[id].lineItemIds.join(TARGETING_VALUE_SEPARATOR),
hb_deal_adbookpsp: values[id].dealIds.join(TARGETING_VALUE_SEPARATOR),
hb_ad_ord_adbookpsp: values[id].adAndOrderIndexes.join(TARGETING_VALUE_SEPARATOR),
hb_adid_c_adbookpsp: values[id].adIds.join(TARGETING_VALUE_SEPARATOR),
hb_ordid_adbookpsp: values[id].orderIds.join(TARGETING_VALUE_SEPARATOR),
};
}

})
return targetingMap;
}

Expand Down
5 changes: 4 additions & 1 deletion modules/colossussspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placement_id));
const validPlacamentId = bid.params && !isNaN(bid.params.placement_id);
const validGroupId = bid.params && !isNaN(bid.params.group_id);

return Boolean(bid.bidId && (validPlacamentId || validGroupId));
},

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/compassBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const spec = {

isBidRequestValid: (bid = {}) => {
const { params, bidId, mediaTypes } = bid;
let valid = Boolean(bidId && params && params.placementId);
let valid = Boolean(bidId && params && (params.placementId || params.endpointId));

if (mediaTypes && mediaTypes[BANNER]) {
valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes);
Expand Down
2 changes: 1 addition & 1 deletion modules/consumableBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Module Name: Consumable Bid Adapter

Module Type: Consumable Adapter

Maintainer: naffis@consumable.com
Maintainer: prebid@consumable.com

# Description

Expand Down
6 changes: 3 additions & 3 deletions modules/gnetBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { _each, parseSizesInput, isEmpty } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { _each, isEmpty, parseSizesInput } from '../src/utils.js';
import { BANNER } from '../src/mediaTypes.js';

const BIDDER_CODE = 'gnet';
const ENDPOINT = 'https://adserver.gnetproject.com/prebid.php';
const ENDPOINT = 'https://service.gnetrtb.com/api/adrequest';

export const spec = {
code: BIDDER_CODE,
Expand All @@ -16,7 +16,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params.websiteId);
return !!(bid.params.websiteId && bid.params.adunitId);
},

/**
Expand Down
8 changes: 4 additions & 4 deletions modules/gnetBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Overview

```
Module Name: Gnet Bidder Adapter
Module Name: Gnet RTB Bidder Adapter
Module Type: Bidder Adapter
Maintainer: roberto.wu@grumft.com
Maintainer: bruno.bonanho@grumft.com
```

# Description

Connect to Gnet Project exchange for bids.
Connect to Gnet RTB exchange for bids.

# Test Parameters
```
Expand All @@ -24,7 +24,7 @@ Connect to Gnet Project exchange for bids.
{
bidder: 'gnet',
params: {
websiteId: '4'
websiteId: '1', adunitId: '1'
}
}
]
Expand Down
147 changes: 147 additions & 0 deletions modules/pilotxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
const BIDDER_CODE = 'pilotx';
const ENDPOINT_URL = '//adn.pilotx.tv/hb'
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: ['banner', 'video'],
aliases: ['pilotx'], // short code
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
let sizesCheck = !!bid.sizes
let paramSizesCheck = !!bid.params.sizes
var sizeConfirmed = false
if (sizesCheck) {
if (bid.sizes.length < 1) {
return false
} else {
sizeConfirmed = true
}
}
if (paramSizesCheck) {
if (bid.params.sizes.length < 1 && !sizeConfirmed) {
return false
} else {
sizeConfirmed = true
}
}
if (!sizeConfirmed) {
return false
}
return !!(bid.params.placementId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
let payloadItems = {};
validBidRequests.forEach(bidRequest => {
let sizes = [];
let placementId = this.setPlacementID(bidRequest.params.placementId)
payloadItems[placementId] = {}
if (bidRequest.sizes.length > 0) {
if (Array.isArray(bidRequest.sizes[0])) {
for (let i = 0; i < bidRequest.sizes.length; i++) {
sizes[i] = [(bidRequest.sizes[i])[0], (bidRequest.sizes[i])[1]]
}
} else {
sizes[0] = [bidRequest.sizes[0], bidRequest.sizes[1]]
}
payloadItems[placementId]['sizes'] = sizes
}
if (bidRequest.mediaTypes != null) {
for (let i in bidRequest.mediaTypes) {
payloadItems[placementId][i] = {
...bidRequest.mediaTypes[i]
}
}
}
let consentTemp = ''
let consentRequiredTemp = false
if (bidderRequest && bidderRequest.gdprConsent) {
consentTemp = bidderRequest.gdprConsent.consentString
// will check if the gdprApplies field was populated with a boolean value (ie from page config). If it's undefined, then default to true
consentRequiredTemp = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : true
}

payloadItems[placementId]['gdprConsentString'] = consentTemp
payloadItems[placementId]['gdprConsentRequired'] = consentRequiredTemp
payloadItems[placementId]['bidId'] = bidRequest.bidId
});
const payload = payloadItems;
const payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: ENDPOINT_URL,
data: payloadString,
};
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
if (serverBody.mediaType == 'banner') {
const bidResponse = {
requestId: serverBody.requestId,
cpm: serverBody.cpm,
width: serverBody.width,
height: serverBody.height,
creativeId: serverBody.creativeId,
currency: serverBody.currency,
netRevenue: false,
ttl: serverBody.ttl,
ad: serverBody.ad,
mediaType: 'banner',
meta: {
mediaType: 'banner',
advertiserDomains: serverBody.advertiserDomains
}
}
bidResponses.push(bidResponse)
} else if (serverBody.mediaType == 'video') {
const bidResponse = {
requestId: serverBody.requestId,
cpm: serverBody.cpm,
width: serverBody.width,
height: serverBody.height,
creativeId: serverBody.creativeId,
currency: serverBody.currency,
netRevenue: false,
ttl: serverBody.ttl,
vastUrl: serverBody.vastUrl,
mediaType: 'video',
meta: {
mediaType: 'video',
advertiserDomains: serverBody.advertiserDomains
}
}
bidResponses.push(bidResponse)
}

return bidResponses;
},

/**
* Formats placement ids for adserver ingestion purposes
* @param {string[]} The placement ID/s in an array
*/
setPlacementID: function (placementId) {
if (Array.isArray(placementId)) {
return placementId.join('#')
}
return placementId
},
}
registerBidder(spec);
Loading

0 comments on commit 1c6cfdf

Please sign in to comment.