diff --git a/src/auction.js b/src/auction.js index fd29aec4b16..6fec1608653 100644 --- a/src/auction.js +++ b/src/auction.js @@ -341,9 +341,31 @@ export function auctionCallbacks(auctionDone, auctionInstance) { } } + function getBidReferrer(bidderRequest) { + const bids = bidderRequest.bids; + const NO_REFERRER = 'no-referrer'; + const NO_REFERRER_LOG = 'Bid with no referrer'; + + if (!bids || bids.length < 1) { + console.warn(NO_REFERRER_LOG); + return NO_REFERRER; + } + + const bid = bids[0]; + + if (bid && bid.params && bid.params.referrer) { + return bid.params.referrer; + } else { + console.warn(NO_REFERRER_LOG); + return NO_REFERRER; + } + } + function addBidResponse(adUnitCode, bid) { let bidderRequest = this; + bid.referrer = getBidReferrer(bidderRequest); + bidResponseMap[bid.requestId] = true; outstandingBidsAdded++; diff --git a/src/targeting.js b/src/targeting.js index d34b717317d..a13e4bb2f1a 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -10,6 +10,8 @@ import { getLastLocation } from './marfeelTools'; const utils = require('./utils.js'); var CONSTANTS = require('./constants.json'); +const bidsByReferrer = {}; + var pbTargetingKeys = []; const MAX_DFP_KEYLENGTH = 20; @@ -344,8 +346,6 @@ export function newTargeting(auctionManager) { return auctionManager.getAdUnitCodes() || []; } - const bidsByReferrer = {}; - /** * bid caching done with all bids specifically for Marfeel purposes due to its own configuration */ @@ -361,9 +361,7 @@ export function newTargeting(auctionManager) { } else { const lastLocation = getLastLocation(); - bidsReceived.forEach(function (bidReceived) { - bidsByReferrer[lastLocation] = (bidsByReferrer[lastLocation]) ? [...bidsByReferrer[lastLocation], bidReceived] : [bidReceived]; - }); + bidsByReferrer[lastLocation] = bidsReceived.filter(bid => bid.referrer === lastLocation); bidsToProcess = bidsByReferrer[lastLocation] || filterBidsByAdUnit(bidsReceived); }