Skip to content

Commit

Permalink
Missena Bid Adapter: allow per page capping (#10863)
Browse files Browse the repository at this point in the history
  • Loading branch information
pdamoc authored Jan 3, 2024
1 parent 665c894 commit 185e97f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
4 changes: 3 additions & 1 deletion modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
const capKey = `missena.missena.capper.remove-bubble.${validBidRequests[0]?.params.apiKey}`;
const capping = safeJSONParse(storage.getDataFromLocalStorage(capKey));
const referer = bidderRequest?.refererInfo?.topmostLocation;
if (
typeof capping?.expiry === 'number' &&
new Date().getTime() < capping?.expiry
new Date().getTime() < capping?.expiry &&
(!capping?.referer || capping?.referer == referer)
) {
logInfo('Missena - Capped');
return [];
Expand Down
41 changes: 39 additions & 2 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { expect } from 'chai';
import { spec, storage } from 'modules/missenaBidAdapter.js';
import { BANNER } from '../../../src/mediaTypes.js';

const REFERRER = 'https://referer';
const REFERRER2 = 'https://referer2';

describe('Missena Adapter', function () {
$$PREBID_GLOBAL$$.bidderSettings = {
missena: {
Expand Down Expand Up @@ -50,7 +53,7 @@ describe('Missena Adapter', function () {
gdprApplies: true,
},
refererInfo: {
topmostLocation: 'https://referer',
topmostLocation: REFERRER,
canonicalUrl: 'https://canonical',
},
};
Expand Down Expand Up @@ -112,7 +115,7 @@ describe('Missena Adapter', function () {
});

it('should send referer information to the request', function () {
expect(payload.referer).to.equal('https://referer');
expect(payload.referer).to.equal(REFERRER);
expect(payload.referer_canonical).to.equal('https://canonical');
});

Expand Down Expand Up @@ -146,6 +149,40 @@ describe('Missena Adapter', function () {
it('should not participate if capped', function () {
expect(cappedRequests.length).to.equal(0);
});

const localStorageDataSamePage = {
[`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]:
JSON.stringify({
expiry: new Date().getTime() + 600_000, // 10 min into the future
referer: REFERRER,
}),
};

getDataFromLocalStorageStub.callsFake(
(key) => localStorageDataSamePage[key],
);
const cappedRequestsSamePage = spec.buildRequests(bids, bidderRequest);

it('should not participate if capped on same page', function () {
expect(cappedRequestsSamePage.length).to.equal(0);
});

const localStorageDataOtherPage = {
[`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]:
JSON.stringify({
expiry: new Date().getTime() + 600_000, // 10 min into the future
referer: REFERRER2,
}),
};

getDataFromLocalStorageStub.callsFake(
(key) => localStorageDataOtherPage[key],
);
const cappedRequestsOtherPage = spec.buildRequests(bids, bidderRequest);

it('should participate if capped on a different page', function () {
expect(cappedRequestsOtherPage.length).to.equal(2);
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 185e97f

Please sign in to comment.