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

Feature : Display counter at Adslot level #2940

Merged
merged 4 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ function slotParams(bidRequest) {
let params = {
id: bidRequest.bidId,
ext: {
dfp_id: bidRequest.adUnitCode
dfp_id: bidRequest.adUnitCode,
display_count: bidRequest.displayCount
Copy link
Member

@mkendall07 mkendall07 Aug 8, 2018

Choose a reason for hiding this comment

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

err small nit with this name. Isn't it more accurate as bidRequestsCount? We don't know if it was displayed. Or auctionParticipationCount

},
banner: transformSizes(bidRequest.sizes),
all: bidRequest.params
Expand Down
18 changes: 18 additions & 0 deletions src/adUnits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { deepAccess } from './utils';

let adUnits = {};

function incrementCounter(adunit) {
adUnits[adunit] = adUnits[adunit] || {};
adUnits[adunit].counter = (deepAccess(adUnits, `${adunit}.counter`) + 1) || 1;
return adUnits[adunit].counter;
Copy link
Member

Choose a reason for hiding this comment

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

why return the count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is increment and get rather than just increment. Will be useful for developer.

}

function getCounter(adunit) {
Copy link
Member

Choose a reason for hiding this comment

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

please add jsdoc definitions to public functions.

return deepAccess(adUnits, `${adunit}.counter`) || 0;
}

exports.adunitCounter = {
Copy link
Member

Choose a reason for hiding this comment

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

new modules should prefer ES6 module interface (ie import / export).

incrementCounter,
getCounter
}
4 changes: 3 additions & 1 deletion src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ajaxBuilder } from 'src/ajax';
import { config, RANDOM } from 'src/config';
import includes from 'core-js/library/fn/array/includes';
import find from 'core-js/library/fn/array/find';
import { adunitCounter } from './adUnits';

var utils = require('./utils.js');
var CONSTANTS = require('./constants.json');
Expand Down Expand Up @@ -95,7 +96,8 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels}) {
sizes: sizes,
bidId: bid.bid_id || utils.getUniqueIdentifierStr(),
bidderRequestId,
auctionId
auctionId,
displayCount: adunitCounter.getCounter(adUnit.code)
}));
}
return bids;
Expand Down
2 changes: 2 additions & 0 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { targeting, getHighestCpmBidsFromBidPool, RENDERED, BID_TARGETING_SET }
import { createHook } from 'src/hook';
import { sessionLoader } from 'src/debugging';
import includes from 'core-js/library/fn/array/includes';
import { adunitCounter } from './adUnits';

const $$PREBID_GLOBAL$$ = getGlobal();
const CONSTANTS = require('./constants.json');
Expand Down Expand Up @@ -367,6 +368,7 @@ $$PREBID_GLOBAL$$.requestBids = createHook('asyncSeries', function ({ bidsBackHa
adUnit.bids = adUnit.bids.filter(bid => bid.bidder !== bidder);
}
});
adunitCounter.incrementCounter(adUnit.code);
});

if (!adUnits || adUnits.length === 0) {
Expand Down
36 changes: 24 additions & 12 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ let VALID_BID_REQUEST = [{
'sizes': [[300, 250]],
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}, {
'bidder': 'medianet',
'params': {
Expand All @@ -33,7 +34,8 @@ let VALID_BID_REQUEST = [{
'sizes': [[300, 251]],
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}],
VALID_BID_REQUEST_INVALID_BIDFLOOR = [{
'bidder': 'medianet',
Expand All @@ -51,7 +53,8 @@ let VALID_BID_REQUEST = [{
'sizes': [[300, 250]],
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}, {
'bidder': 'medianet',
'params': {
Expand All @@ -67,7 +70,8 @@ let VALID_BID_REQUEST = [{
'sizes': [[300, 251]],
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}],
VALID_AUCTIONDATA = {
'timeout': config.getConfig('bidderTimeout'),
Expand Down Expand Up @@ -103,7 +107,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down Expand Up @@ -133,7 +138,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down Expand Up @@ -181,7 +187,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down Expand Up @@ -210,7 +217,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down Expand Up @@ -372,7 +380,8 @@ let VALID_BID_REQUEST = [{
'sizes': [300, 250],
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}, {
'bidder': 'medianet',
'params': {
Expand All @@ -388,7 +397,8 @@ let VALID_BID_REQUEST = [{
'sizes': [300, 251],
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'displayCount': 1
}],
VALID_BIDDER_REQUEST_WITH_GDPR = {
'gdprConsent': {
Expand Down Expand Up @@ -429,7 +439,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down Expand Up @@ -458,7 +469,8 @@ let VALID_BID_REQUEST = [{
x: 100,
y: 100
}
}
},
'display_count': 1
},
'banner': [{
'w': 300,
Expand Down
23 changes: 23 additions & 0 deletions test/spec/unit/adUnits_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect } from 'chai';
import { adunitCounter } from 'src/adUnits';

describe('Adunit Counter', function () {
const ADUNIT_ID_1 = 'test1';
const ADUNIT_ID_2 = 'test2';

it('increments and checks counter of adunit 1', function () {
adunitCounter.incrementCounter(ADUNIT_ID_1);
expect(adunitCounter.getCounter(ADUNIT_ID_1)).to.be.equal(1);
});
it('checks counter of adunit 2', function () {
expect(adunitCounter.getCounter(ADUNIT_ID_2)).to.be.equal(0);
});
it('increments and checks counter of adunit 1', function () {
adunitCounter.incrementCounter(ADUNIT_ID_1);
expect(adunitCounter.getCounter(ADUNIT_ID_1)).to.be.equal(2);
});
it('increments and checks counter of adunit 2', function () {
adunitCounter.incrementCounter(ADUNIT_ID_2);
expect(adunitCounter.getCounter(ADUNIT_ID_2)).to.be.equal(1);
});
});