From 58ea9fc35323fe6b03a148a9bb15840bd1896a44 Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Thu, 7 Nov 2019 09:34:31 +0100 Subject: [PATCH 1/6] added isBidCached method --- src/prebid.js | 22 ++++++++++++++++++++-- src/targeting.js | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/prebid.js b/src/prebid.js index 575e98d4054..bc8e397a32b 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -7,14 +7,14 @@ import { userSync } from './userSync.js'; import { loadScript } from './adloader'; import { config } from './config'; import { auctionManager } from './auctionManager'; -import { targeting, getHighestCpmBidsFromBidPool } from './targeting'; +import { targeting, getHighestCpmBidsFromBidPool, bidsByReferrer } from './targeting'; import { hook } from './hook'; import { sessionLoader } from './debugging'; import includes from 'core-js/library/fn/array/includes'; import { adunitCounter } from './adUnits'; import { isRendererRequired, executeRenderer } from './Renderer'; import { createBid } from './bidfactory'; -import { setLastLocationFromLastAdUnit } from './marfeelTools'; +import { setLastLocationFromLastAdUnit, getLastLocation } from './marfeelTools'; const $$PREBID_GLOBAL$$ = getGlobal(); const CONSTANTS = require('./constants.json'); @@ -841,4 +841,22 @@ $$PREBID_GLOBAL$$.processQueue = function() { processQueue($$PREBID_GLOBAL$$.cmd); }; +/** + * @alias module:pbjs.isBidCached + */ +$$PREBID_GLOBAL$$.isBidCached = function(bidId) { + var lastLocation = getLastLocation(); + var bidsIds = []; + + if (!bidsByReferrer[lastLocation] || bidsByReferrer[lastLocation].length < 2) { + return false; + } + + bidsByReferrer[lastLocation].forEach(function(bid) { + bidsIds.push(bid.adId); + }); + + return bidsIds.indexOf(bidId) !== -1 && bidsIds.indexOf(bidId) !== bidsIds.lastIndexOf(bidId); +} + export default $$PREBID_GLOBAL$$; diff --git a/src/targeting.js b/src/targeting.js index d34b717317d..81408b14426 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'); +export 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 */ From aa58ef3dfeb4da5e6eb7758443be50fa1902a9a5 Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Fri, 8 Nov 2019 09:44:10 +0100 Subject: [PATCH 2/6] filter by referer --- src/auction.js | 2 ++ src/prebid.js | 8 ++++++-- src/targeting.js | 4 +--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/auction.js b/src/auction.js index fd29aec4b16..085aafef559 100644 --- a/src/auction.js +++ b/src/auction.js @@ -344,6 +344,8 @@ export function auctionCallbacks(auctionDone, auctionInstance) { function addBidResponse(adUnitCode, bid) { let bidderRequest = this; + bid.referer = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + bidResponseMap[bid.requestId] = true; outstandingBidsAdded++; diff --git a/src/prebid.js b/src/prebid.js index bc8e397a32b..366b6af9555 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -841,10 +841,14 @@ $$PREBID_GLOBAL$$.processQueue = function() { processQueue($$PREBID_GLOBAL$$.cmd); }; +$$PREBID_GLOBAL$$.logBidsByReferrer = function() { + console.log(bidsByReferrer); +}; + /** * @alias module:pbjs.isBidCached */ -$$PREBID_GLOBAL$$.isBidCached = function(bidId) { +$$PREBID_GLOBAL$$.isBidCached = function(adId) { var lastLocation = getLastLocation(); var bidsIds = []; @@ -856,7 +860,7 @@ $$PREBID_GLOBAL$$.isBidCached = function(bidId) { bidsIds.push(bid.adId); }); - return bidsIds.indexOf(bidId) !== -1 && bidsIds.indexOf(bidId) !== bidsIds.lastIndexOf(bidId); + return bidsIds.indexOf(adId) !== -1; } export default $$PREBID_GLOBAL$$; diff --git a/src/targeting.js b/src/targeting.js index 81408b14426..7d76b612fbd 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -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.referer === lastLocation); bidsToProcess = bidsByReferrer[lastLocation] || filterBidsByAdUnit(bidsReceived); } From 68c67827f9b6ea99888728813829decc47d134ff Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Fri, 8 Nov 2019 10:29:23 +0100 Subject: [PATCH 3/6] new method getBidReferer --- src/auction.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/auction.js b/src/auction.js index 085aafef559..b978cea4d94 100644 --- a/src/auction.js +++ b/src/auction.js @@ -341,10 +341,30 @@ export function auctionCallbacks(auctionDone, auctionInstance) { } } + function getBidReferer(bidderRequest, adId) { + const bids = bidderRequest.bids; + const NO_REFERER = 'no-referer'; + const NO_REFERER_LOG = 'Bid with no referer'; + + if (!bids) { + console.warn(NO_REFERER_LOG); + return NO_REFERER; + } + + const bid = bids.filter(bid => bid.adId === adId)[0]; + + if (bid && bid.params && bid.params.referer) { + return bid.params.referer; + } else { + console.warn(NO_REFERER_LOG); + return NO_REFERER; + } + } + function addBidResponse(adUnitCode, bid) { let bidderRequest = this; - bid.referer = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + bid.referer = getBidReferer(bidderRequest, bid.adId); bidResponseMap[bid.requestId] = true; From e7389b2464f58d4329ddf346bd3ab82cee56d46b Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Tue, 12 Nov 2019 15:43:51 +0100 Subject: [PATCH 4/6] changed bidsByReferrer logic --- src/auction.js | 24 ++++++++++++------------ src/targeting.js | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/auction.js b/src/auction.js index b978cea4d94..6fec1608653 100644 --- a/src/auction.js +++ b/src/auction.js @@ -341,30 +341,30 @@ export function auctionCallbacks(auctionDone, auctionInstance) { } } - function getBidReferer(bidderRequest, adId) { + function getBidReferrer(bidderRequest) { const bids = bidderRequest.bids; - const NO_REFERER = 'no-referer'; - const NO_REFERER_LOG = 'Bid with no referer'; + const NO_REFERRER = 'no-referrer'; + const NO_REFERRER_LOG = 'Bid with no referrer'; - if (!bids) { - console.warn(NO_REFERER_LOG); - return NO_REFERER; + if (!bids || bids.length < 1) { + console.warn(NO_REFERRER_LOG); + return NO_REFERRER; } - const bid = bids.filter(bid => bid.adId === adId)[0]; + const bid = bids[0]; - if (bid && bid.params && bid.params.referer) { - return bid.params.referer; + if (bid && bid.params && bid.params.referrer) { + return bid.params.referrer; } else { - console.warn(NO_REFERER_LOG); - return NO_REFERER; + console.warn(NO_REFERRER_LOG); + return NO_REFERRER; } } function addBidResponse(adUnitCode, bid) { let bidderRequest = this; - bid.referer = getBidReferer(bidderRequest, bid.adId); + bid.referrer = getBidReferrer(bidderRequest); bidResponseMap[bid.requestId] = true; diff --git a/src/targeting.js b/src/targeting.js index 7d76b612fbd..e2b03a51b97 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -361,7 +361,7 @@ export function newTargeting(auctionManager) { } else { const lastLocation = getLastLocation(); - bidsByReferrer[lastLocation] = bidsReceived.filter(bid => bid.referer === lastLocation); + bidsByReferrer[lastLocation] = bidsReceived.filter(bid => bid.referrer === lastLocation); bidsToProcess = bidsByReferrer[lastLocation] || filterBidsByAdUnit(bidsReceived); } From 7748d7b918f79af5eab2569634c77b54ccdb0fbd Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Tue, 12 Nov 2019 15:50:55 +0100 Subject: [PATCH 5/6] remove script methods --- src/prebid.js | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/prebid.js b/src/prebid.js index 366b6af9555..575e98d4054 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -7,14 +7,14 @@ import { userSync } from './userSync.js'; import { loadScript } from './adloader'; import { config } from './config'; import { auctionManager } from './auctionManager'; -import { targeting, getHighestCpmBidsFromBidPool, bidsByReferrer } from './targeting'; +import { targeting, getHighestCpmBidsFromBidPool } from './targeting'; import { hook } from './hook'; import { sessionLoader } from './debugging'; import includes from 'core-js/library/fn/array/includes'; import { adunitCounter } from './adUnits'; import { isRendererRequired, executeRenderer } from './Renderer'; import { createBid } from './bidfactory'; -import { setLastLocationFromLastAdUnit, getLastLocation } from './marfeelTools'; +import { setLastLocationFromLastAdUnit } from './marfeelTools'; const $$PREBID_GLOBAL$$ = getGlobal(); const CONSTANTS = require('./constants.json'); @@ -841,26 +841,4 @@ $$PREBID_GLOBAL$$.processQueue = function() { processQueue($$PREBID_GLOBAL$$.cmd); }; -$$PREBID_GLOBAL$$.logBidsByReferrer = function() { - console.log(bidsByReferrer); -}; - -/** - * @alias module:pbjs.isBidCached - */ -$$PREBID_GLOBAL$$.isBidCached = function(adId) { - var lastLocation = getLastLocation(); - var bidsIds = []; - - if (!bidsByReferrer[lastLocation] || bidsByReferrer[lastLocation].length < 2) { - return false; - } - - bidsByReferrer[lastLocation].forEach(function(bid) { - bidsIds.push(bid.adId); - }); - - return bidsIds.indexOf(adId) !== -1; -} - export default $$PREBID_GLOBAL$$; From 2e709578b2a4db738616f28855de00a3f9753d2f Mon Sep 17 00:00:00 2001 From: joanmirallesmrf Date: Tue, 12 Nov 2019 16:00:29 +0100 Subject: [PATCH 6/6] bidsByReferrer as private --- src/targeting.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targeting.js b/src/targeting.js index e2b03a51b97..a13e4bb2f1a 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -10,7 +10,7 @@ import { getLastLocation } from './marfeelTools'; const utils = require('./utils.js'); var CONSTANTS = require('./constants.json'); -export const bidsByReferrer = {}; +const bidsByReferrer = {}; var pbTargetingKeys = [];