Skip to content

Commit

Permalink
bugfix for targeting not setting for all adslots (prebid#2615)
Browse files Browse the repository at this point in the history
* bugfix for targeting not setting for all adslots

* updated var names
  • Loading branch information
jaiminpanchal27 authored and dluxemburg committed Jul 17, 2018
1 parent b97d2e8 commit aed5cae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/auctionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export function newAuctionManager() {
return getStandardBidderSettings()[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING];
};

auctionManager.setStatusForBids = function(adId, status) {
let bid = auctionManager.findBidByAdId(adId);
if (bid) bid.status = status;
}

function _addAuction(auction) {
_auctions.push(auction);
}
Expand Down
10 changes: 9 additions & 1 deletion src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,22 @@ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit) {
}

// get our ad unit codes
var targetingSet = targeting.getAllTargeting(adUnit);
let targetingSet = targeting.getAllTargeting(adUnit);

// first reset any old targeting
targeting.resetPresetTargeting(adUnit);

// now set new targeting keys
targeting.setTargetingForGPT(targetingSet);

Object.keys(targetingSet).forEach((adUnitCode) => {
Object.keys(targetingSet[adUnitCode]).forEach((targetingKey) => {
if (targetingKey === 'hb_adid') {
auctionManager.setStatusForBids(targetingSet[adUnitCode][targetingKey], BID_TARGETING_SET);
}
});
});

// emit event
events.emit(SET_TARGETING, targetingSet);
};
Expand Down
5 changes: 0 additions & 5 deletions src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,6 @@ export function newTargeting(auctionManager) {
*/
function getWinningBidTargeting(adUnitCodes, bidsReceived) {
let winners = targeting.getWinningBids(adUnitCodes, bidsReceived);
winners.forEach((winner) => {
winner.status = BID_TARGETING_SET;
});

// TODO : Add losing bids to pool from here ?
let standardKeys = getStandardKeys();

winners = winners.map(winner => {
Expand Down
5 changes: 3 additions & 2 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ describe('Unit: Prebid Module', function () {
let auction;
let ajaxStub;
let cbTimeout = 3000;
let auctionManagerInstance = newAuctionManager();
let targeting = newTargeting(auctionManagerInstance);
let targeting;

let RESPONSE = {
'version': '0.0.1',
Expand Down Expand Up @@ -454,6 +453,8 @@ describe('Unit: Prebid Module', function () {
})

beforeEach(() => {
let auctionManagerInstance = newAuctionManager();
targeting = newTargeting(auctionManagerInstance);
let adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250], [300, 600]],
Expand Down

0 comments on commit aed5cae

Please sign in to comment.