Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event updates #5288

Merged
105 changes: 94 additions & 11 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,55 @@ 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
*/
let 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].every(utils.isStr)) {
idettman marked this conversation as resolved.
Show resolved Hide resolved
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].every(utils.isStr)) {
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].every(utils.isStr)) {
return wurlMap[`${auctionId}${adId}`];
}
}

/**
* remove all cached wurls
*/
export function resetWurlMap() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used?

Also, why not just

wurlMap = {};?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@idettman Bump

Copy link
Contributor Author

@idettman idettman Jun 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used for the unit tests. Good call on obj = {}, the performance gains of re-using the same obj are not worth the extra code when the performance impact is small.

wurlMap = {};
}

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 @@ -522,7 +567,7 @@ const OPEN_RTB_PROTOCOL = {
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 +589,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 +618,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 +643,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 +705,28 @@ 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.isStr(bidId)) {
bidObject.pbsBidId = bidId;
}

// store wurl by auctionId and adId so it can be accessed from the BID_WON event handler
if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.win'))) {
addWurl(bidRequest.auctionId, bidObject.adId, utils.deepAccess(bid, 'ext.prebid.events.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') {
// The removal of hb_winurl and hb_bidid targeting values is temporary
// once we get through the transition, this block will be removed.
if (utils.isPlainObject(extPrebidTargeting)) {
// If wurl exists, remove hb_winurl and hb_bidid targeting attributes
if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.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 +838,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.isStr(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 +936,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,
idettman marked this conversation as resolved.
Show resolved Hide resolved
'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
2 changes: 1 addition & 1 deletion src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export const callPrebidCache = hook('async', function(auctionInstance, bidRespon
afterBidAdded();
}
}
});
}, bidderRequest);
}, 'callPrebidCache');

// Postprocess the bids so that all the universal properties exist, no matter which bidder they came from.
Expand Down
12 changes: 9 additions & 3 deletions src/videoCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*/

import { ajax } from './ajax.js';
import { config } from '../src/config.js';
import { config } from './config.js';
import * as utils from './utils.js';

/**
* @typedef {object} CacheableUrlBid
Expand Down Expand Up @@ -70,6 +71,10 @@ function toStorageRequest(bid) {
if (config.getConfig('cache.vasttrack')) {
payload.bidder = bid.bidder;
payload.bidid = bid.requestId;
// function has a thisArg set to bidderRequest for accessing the auctionStart
if (utils.isPlainObject(this) && this.hasOwnProperty('auctionStart')) {
payload.timestamp = this.auctionStart;
}
}

if (typeof bid.customCacheKey === 'string' && bid.customCacheKey !== '') {
Expand Down Expand Up @@ -126,11 +131,12 @@ function shimStorageCallback(done) {
*
* @param {CacheableBid[]} bids A list of bid objects which should be cached.
* @param {videoCacheStoreCallback} [done] An optional callback which should be executed after
* @param {BidderRequest} [bidderRequest]
* the data has been stored in the cache.
*/
export function store(bids, done) {
export function store(bids, done, bidderRequest) {
const requestData = {
puts: bids.map(toStorageRequest)
puts: bids.map(toStorageRequest, bidderRequest)
};

ajax(config.getConfig('cache.url'), shimStorageCallback(done), JSON.stringify(requestData), {
Expand Down
Loading