Skip to content

Commit

Permalink
Snigel Bid Adapter: add placement counter and adapter version field (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
snigelweb authored Oct 31, 2024
1 parent 45e9277 commit 0209218
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
14 changes: 14 additions & 0 deletions modules/snigelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SESSION_ID_KEY = '_sn_session_pba';
const getConfig = config.getConfig;
const storageManager = getStorageManager({bidderCode: BIDDER_CODE});
const refreshes = {};
const placementCounters = {};
const pageViewId = generateUUID();
const pageViewStart = new Date().getTime();
let auctionCounter = 0;
Expand Down Expand Up @@ -46,6 +47,7 @@ export const spec = {
cur: getCurrencies(),
test: getTestFlag(),
version: 'v' + '$prebid.version$',
adapterVersion: '2.0',
gpp: deepAccess(bidderRequest, 'gppConsent.gppString') || deepAccess(bidderRequest, 'ortb2.regs.gpp'),
gpp_sid:
deepAccess(bidderRequest, 'gppConsent.applicableSections') || deepAccess(bidderRequest, 'ortb2.regs.gpp_sid'),
Expand All @@ -71,6 +73,7 @@ export const spec = {
gpid: deepAccess(r, 'ortb2Imp.ext.gpid'),
pbadslot: deepAccess(r, 'ortb2Imp.ext.data.pbadslot') || deepAccess(r, 'ortb2Imp.ext.gpid'),
name: r.params.placement,
counter: getPlacementCounter(r.params.placement),
sizes: r.sizes,
floor: getPriceFloor(r, BANNER, FLOOR_MATCH_ALL_SIZES),
refresh: getRefreshInformation(r.adUnitCode),
Expand Down Expand Up @@ -182,6 +185,17 @@ function getRefreshInformation(adUnitCode) {
};
}

function getPlacementCounter(placement) {
const counter = placementCounters[placement];
if (counter === undefined) {
placementCounters[placement] = 0;
return 0;
}

placementCounters[placement]++;
return placementCounters[placement];
}

function mapIdToRequestId(id, bidRequest) {
return bidRequest.bidderRequest.bids.filter((bid) => bid.adUnitCode === id)[0].bidId;
}
Expand Down
69 changes: 51 additions & 18 deletions test/spec/modules/snigelBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,50 @@ describe('snigelBidAdapter', function () {
expect(data.placements[2].refresh.count).to.equal(1);
expect(data.placements[2].refresh.time).to.be.greaterThanOrEqual(0);
});

it('should increment auction counter upon every request', function () {
const bidderRequest = makeBidderRequest({});

let request = spec.buildRequests([], bidderRequest);
expect(request).to.have.property('data');
let data = JSON.parse(request.data);
const previousCounter = data.counter;

request = spec.buildRequests([], bidderRequest);
expect(request).to.have.property('data');
data = JSON.parse(request.data);
expect(data.counter).to.equal(previousCounter + 1);
});

it('should increment placement counter for each placement', function () {
const bidderRequest = Object.assign({}, BASE_BIDDER_REQUEST);
const topLeaderboard = makeBidRequest({adUnitCode: 'top_leaderboard', params: {placement: 'ros'}});
const bottomLeaderboard = makeBidRequest({adUnitCode: 'bottom_leaderboard', params: {placement: 'ros'}});
const sidebar = makeBidRequest({adUnitCode: 'sidebar', params: {placement: 'other'}});

let request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest);
expect(request).to.have.property('data');
let data = JSON.parse(request.data);
const previousCounters = {};
data.placements.forEach((placement) => {
previousCounters[placement.name] = Math.max(previousCounters[placement.name] || 0, placement.counter);
});

request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest);
expect(request).to.have.property('data');
data = JSON.parse(request.data);
expect(data).to.have.property('placements');
expect(data.placements.length).to.equal(3);
expect(data.placements[0].id).to.equal('top_leaderboard');
expect(previousCounters).to.have.property(data.placements[0].name);
expect(data.placements[0].counter).to.equal(previousCounters[data.placements[0].name] + 1);
expect(data.placements[1].id).to.equal('bottom_leaderboard');
expect(previousCounters).to.have.property(data.placements[1].name);
expect(data.placements[1].counter).to.equal(previousCounters[data.placements[1].name] + 2);
expect(data.placements[2].id).to.equal('sidebar');
expect(previousCounters).to.have.property(data.placements[2].name);
expect(data.placements[2].counter).to.equal(previousCounters[data.placements[2].name] + 1);
});
});

describe('interpretResponse', function () {
Expand Down Expand Up @@ -347,7 +391,7 @@ describe('snigelBidAdapter', function () {
expect(sync.url).to.equal(`https://somesyncurl?gdpr=1&gdpr_consent=${DUMMY_GDPR_CONSENT_STRING}`);
});

it('should omit session ID if no device access', function() {
it('should omit session ID if no device access', function () {
const bidderRequest = makeBidderRequest();
const unregisterRule = registerActivityControl(ACTIVITY_ACCESS_DEVICE, 'denyAccess', () => {
return {allow: false, reason: 'no consent'};
Expand All @@ -373,9 +417,9 @@ describe('snigelBidAdapter', function () {
},
vendor: {
consents: {[spec.gvlid]: true},
}
},
},
}
},
});
let request = spec.buildRequests([], baseBidderRequest);
expect(request).to.have.property('data');
Expand All @@ -388,25 +432,14 @@ describe('snigelBidAdapter', function () {
data = JSON.parse(request.data);
expect(data.gdprConsent).to.be.false;

bidderRequest = {...baseBidderRequest, ...{gdprConsent: {vendorData: {vendor: {consents: {[spec.gvlid]: false}}}}}};
bidderRequest = {
...baseBidderRequest,
...{gdprConsent: {vendorData: {vendor: {consents: {[spec.gvlid]: false}}}}},
};
request = spec.buildRequests([], bidderRequest);
expect(request).to.have.property('data');
data = JSON.parse(request.data);
expect(data.gdprConsent).to.be.false;
});

it('should increment auction counter upon every request', function() {
const bidderRequest = makeBidderRequest({});

let request = spec.buildRequests([], bidderRequest);
expect(request).to.have.property('data');
let data = JSON.parse(request.data);
const previousCounter = data.counter;

request = spec.buildRequests([], bidderRequest);
expect(request).to.have.property('data');
data = JSON.parse(request.data);
expect(data.counter).to.equal(previousCounter + 1);
});
});
});

0 comments on commit 0209218

Please sign in to comment.