-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why return the count? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new modules should prefer ES6 module interface (ie |
||
incrementCounter, | ||
getCounter | ||
} |
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); | ||
}); | ||
}); |
There was a problem hiding this comment.
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. OrauctionParticipationCount