Skip to content

Commit

Permalink
event updates
Browse files Browse the repository at this point in the history
  • Loading branch information
idettman committed May 27, 2020
1 parent 67a1b1e commit d5daa05
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 14 deletions.
96 changes: 85 additions & 11 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,48 @@ let nativeEventTrackerMethodMap = {
*/
let bidIdMap = {};
let nativeAssetCache = {}; // store processed native params to preserve

/**
* map wurl to auction id and adId for use in the BID_WON event
*/
`const wurlMap = {};
/**
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
* @param {string} wurl events.winurl passed from prebidServer as wurl
*/
function addWurl(auctionId, adId, wurl) {
if (![auctionId, adId].some(utils.isEmptyStr)) {
wurlMap[`${auctionId}${adId}`] = wurl;
}
}
/**
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
*/
function removeWurl(auctionId, adId) {
if (![auctionId, adId].some(utils.isEmptyStr)) {
wurlMap[`${auctionId}${adId}`] = undefined;
}
}
/**
* @param {string} auctionId
* @param {string} adId generated value set to bidObject.adId by bidderFactory Bid()
* @return {(string|undefined)} events.winurl which was passed as wurl
*/
function getWurl(auctionId, adId) {
if (![auctionId, adId].some(utils.isEmptyStr)) {
return wurlMap[`${auctionId}${adId}`];
}
}
const OPEN_RTB_PROTOCOL = {
buildRequest(s2sBidRequest, bidRequests, adUnits) {
let imps = [];
let aliases = {};
const firstBidRequest = bidRequests[0];
// transform ad unit into array of OpenRTB impression objects
adUnits.forEach(adUnit => {
Expand Down Expand Up @@ -515,14 +553,14 @@ const OPEN_RTB_PROTOCOL = {
* @type {(string|undefined)}
*/
const pbAdSlot = utils.deepAccess(adUnit, 'fpd.context.pbAdSlot');
if (typeof pbAdSlot === 'string' && pbAdSlot) {
if (!utils.isEmptyStr(pbAdSlot)) {
utils.deepSetValue(imp, 'ext.context.data.adslot', pbAdSlot);
}
Object.assign(imp, mediaTypes);
// if storedAuctionResponse has been set, pass SRID
const storedAuctionResponseBid = find(bidRequests[0].bids, bid => (bid.adUnitCode === adUnit.code && bid.storedAuctionResponse));
const storedAuctionResponseBid = find(firstBidRequest.bids, bid => (bid.adUnitCode === adUnit.code && bid.storedAuctionResponse));
if (storedAuctionResponseBid) {
utils.deepSetValue(imp, 'ext.prebid.storedauctionresponse.id', storedAuctionResponseBid.storedAuctionResponse.toString());
}
Expand All @@ -544,6 +582,8 @@ const OPEN_RTB_PROTOCOL = {
test: getConfig('debug') ? 1 : 0,
ext: {
prebid: {
// set ext.prebid.auctiontimestamp with the auction timestamp. Data type is long integer.
auctiontimestamp: firstBidRequest.auctionStart,
targeting: {
// includewinners is always true for openrtb
includewinners: true,
Expand Down Expand Up @@ -571,9 +611,9 @@ const OPEN_RTB_PROTOCOL = {
request.cur = [adServerCur[0]];
}
_appendSiteAppDevice(request, bidRequests[0].refererInfo.referer);
_appendSiteAppDevice(request, firstBidRequest.refererInfo.referer);
const digiTrust = _getDigiTrustQueryParams(bidRequests && bidRequests[0]);
const digiTrust = _getDigiTrustQueryParams(firstBidRequest);
if (digiTrust) {
utils.deepSetValue(request, 'user.ext.digitrust', digiTrust);
}
Expand All @@ -596,19 +636,19 @@ const OPEN_RTB_PROTOCOL = {
}
if (bidRequests) {
if (bidRequests[0].gdprConsent) {
if (firstBidRequest.gdprConsent) {
// note - gdprApplies & consentString may be undefined in certain use-cases for consentManagement module
let gdprApplies;
if (typeof bidRequests[0].gdprConsent.gdprApplies === 'boolean') {
gdprApplies = bidRequests[0].gdprConsent.gdprApplies ? 1 : 0;
if (typeof firstBidRequest.gdprConsent.gdprApplies === 'boolean') {
gdprApplies = firstBidRequest.gdprConsent.gdprApplies ? 1 : 0;
}
utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies);
utils.deepSetValue(request, 'user.ext.consent', bidRequests[0].gdprConsent.consentString);
utils.deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString);
}
// US Privacy (CCPA) support
if (bidRequests[0].uspConsent) {
utils.deepSetValue(request, 'regs.ext.us_privacy', bidRequests[0].uspConsent);
if (firstBidRequest.uspConsent) {
utils.deepSetValue(request, 'regs.ext.us_privacy', firstBidRequest.uspConsent);
}
}
Expand Down Expand Up @@ -658,10 +698,26 @@ const OPEN_RTB_PROTOCOL = {
bidRequest.serverResponseTimeMs = serverResponseTimeMs;
}
const extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting');
// Look for seatbid[].bid[].ext.prebid.bidid and place it in the bidResponse object for use in analytics adapters as 'pbsBidId'
const bidId = utils.deepAccess(bid, 'ext.prebid.bidid');
if (!utils.isEmptyStr(bidId)) {
bidObject.pbsBidId = bidId;
}
// store wurl by auctionId and adId so it can be access from the BID_WON event handler
if (!utils.isEmptyStr(utils.deepAccess(bid, 'ext.prebid.event.win'))) {
addWurl(bidRequest.auctionId, bidObject.adId, utils.deepAccess(bid, 'ext.prebid.event.win'));
}
let extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting');
// If ext.prebid.targeting exists, add it as a property value named 'adserverTargeting'
if (extPrebidTargeting && typeof extPrebidTargeting === 'object') {
// If wurl exists, remove hb_winurl and hb_bidid targeting attributes
if (!utils.isEmptyStr(utils.deepAccess(bid, 'ext.prebid.event.win'))) {
extPrebidTargeting = utils.getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting)
.filter(i => (i.indexOf('hb_winurl') === -1 && i.indexOf('hb_bidid') === -1)));
}
bidObject.adserverTargeting = extPrebidTargeting;
}
Expand Down Expand Up @@ -773,6 +829,21 @@ const OPEN_RTB_PROTOCOL = {
}
};

/**
* BID_WON event to request the wurl
* @param {Bid} bid the winning bid object
*/
function bidWonHandler(bid) {
const wurl = getWurl(bid.auctionId, bid.adId);
if (!utils.isEmptyStr(wurl)) {
utils.logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`);
utils.triggerPixel(wurl);

// remove from wurl cache, since the wurl url was called
removeWurl(bid.auctionId, bid.adId);
}
}

/**
* Bidder adapter for Prebid Server
*/
Expand Down Expand Up @@ -856,6 +927,9 @@ export function PrebidServer() {
doClientSideSyncs(requestedBidders);
}

// Listen for bid won to call wurl
events.on(EVENTS.BID_WON, bidWonHandler);

return Object.assign(this, {
callBids: baseAdapter.callBids,
setBidderCode: baseAdapter.setBidderCode,
Expand Down
2 changes: 1 addition & 1 deletion modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function sendMessage(auctionId, bidWonId) {
function formatBid(bid) {
return utils.pick(bid, [
'bidder',
'bidId', bidId => utils.deepAccess(bid, 'bidResponse.seatBidId') || bidId,
'bidId', bidId => utils.deepAccess(bid, 'bidResponse.pbsBidId') || utils.deepAccess(bid, 'bidResponse.seatBidId') || bidId,
'status',
'error',
'source', (source, bid) => {
Expand Down
3 changes: 3 additions & 0 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ export const spec = {
utils.deepSetValue(data.imp[0], 'ext.prebid.storedauctionresponse.id', bidRequest.storedAuctionResponse.toString());
}

// set ext.prebid.auctiontimestamp using auction time
utils.deepSetValue(data.imp[0], 'ext.prebid.auctiontimestamp', bidderRequest.auctionStart);

return {
method: 'POST',
url: VIDEO_ENDPOINT,
Expand Down
4 changes: 3 additions & 1 deletion src/adapterManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src})
'fpd',
'mediaType',
'renderer',
'storedAuctionResponse'
'storedAuctionResponse',
'seatBidId',
'pbsBidId'
]));

let {
Expand Down
Loading

0 comments on commit d5daa05

Please sign in to comment.