Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Missena Bid Adapter : refactor getUserSyncs, send screen size #12497

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 16 additions & 14 deletions modules/missenaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function toPayload(bidRequest, bidderRequest) {
payload.schain = bidRequest.schain;
payload.coppa = bidderRequest?.ortb2?.regs?.coppa ? 1 : 0;
payload.autoplay = isAutoplayEnabled() === true ? 1 : 0;
payload.screen = { height: screen.height, width: screen.width };

return {
method: 'POST',
Expand Down Expand Up @@ -130,6 +131,8 @@ export const spec = {
return [];
}

this.msnaApiKey = validBidRequests[0]?.params.apiKey;

return validBidRequests.map((bidRequest) =>
toPayload(bidRequest, bidderRequest),
);
Expand All @@ -154,26 +157,25 @@ export const spec = {
getUserSyncs: function (
syncOptions,
serverResponses,
gdprConsent,
gdprConsent = {},
uspConsent,
) {
if (!syncOptions.iframeEnabled) {
if (!syncOptions.iframeEnabled || !this.msnaApiKey) {
return [];
}

let gdprParams = '';
if (
gdprConsent &&
'gdprApplies' in gdprConsent &&
typeof gdprConsent.gdprApplies === 'boolean'
) {
gdprParams = `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${
gdprConsent.consentString
}`;
const url = new URL('https://sync.missena.io/iframe');
url.searchParams.append('t', this.msnaApiKey);

if (typeof gdprConsent.gdprApplies === 'boolean') {
url.searchParams.append('gdpr', Number(gdprConsent.gdprApplies));
url.searchParams.append('gdpr_consent', gdprConsent.consentString);
}
if (uspConsent) {
url.searchParams.append('us_privacy', uspConsent);
}
return [
{ type: 'iframe', url: 'https://sync.missena.io/iframe' + gdprParams },
];

return [{ type: 'iframe', url: url.href }];
},
/**
* Register bidder specific code, which will execute if bidder timed out after an auction
Expand Down
16 changes: 11 additions & 5 deletions test/spec/modules/missenaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as autoplay from 'libraries/autoplayDetection/autoplay.js';
const REFERRER = 'https://referer';
const REFERRER2 = 'https://referer2';
const COOKIE_DEPRECATION_LABEL = 'test';
const API_KEY = 'PA-XXXXXX';

describe('Missena Adapter', function () {
$$PREBID_GLOBAL$$.bidderSettings = {
Expand All @@ -30,7 +31,7 @@ describe('Missena Adapter', function () {
},
},
params: {
apiKey: 'PA-34745704',
apiKey: API_KEY,
placement: 'sticky',
formats: ['sticky-banner'],
},
Expand All @@ -57,7 +58,7 @@ describe('Missena Adapter', function () {
sizes: [[1, 1]],
mediaTypes: { banner: { sizes: [[1, 1]] } },
params: {
apiKey: 'PA-34745704',
apiKey: API_KEY,
placement: 'sticky',
formats: ['sticky-banner'],
},
Expand Down Expand Up @@ -172,6 +173,11 @@ describe('Missena Adapter', function () {
expect(payload.ik).to.equal(window.msna_ik);
});

it('should send screen', function () {
expect(payload.screen.width).to.equal(screen.width);
expect(payload.screen.height).to.equal(screen.height);
});

getDataFromLocalStorageStub.restore();
getDataFromLocalStorageStub = sinon.stub(
storage,
Expand Down Expand Up @@ -299,7 +305,7 @@ describe('Missena Adapter', function () {

expect(userSync.length).to.be.equal(1);
expect(userSync[0].type).to.be.equal('iframe');
expect(userSync[0].url).to.be.equal(syncFrameUrl);
expect(userSync[0].url).to.be.equal(`${syncFrameUrl}?t=${API_KEY}`);
});

it('should return empty array when iframeEnabled is false', function () {
Expand All @@ -312,7 +318,7 @@ describe('Missena Adapter', function () {
gdprApplies: true,
consentString,
});
const expectedUrl = `${syncFrameUrl}?gdpr=1&gdpr_consent=${consentString}`;
const expectedUrl = `${syncFrameUrl}?t=${API_KEY}&gdpr=1&gdpr_consent=${consentString}`;
expect(userSync.length).to.be.equal(1);
expect(userSync[0].type).to.be.equal('iframe');
expect(userSync[0].url).to.be.equal(expectedUrl);
Expand All @@ -322,7 +328,7 @@ describe('Missena Adapter', function () {
gdprApplies: false,
consentString,
});
const expectedUrl = `${syncFrameUrl}?gdpr=0&gdpr_consent=${consentString}`;
const expectedUrl = `${syncFrameUrl}?t=${API_KEY}&gdpr=0&gdpr_consent=${consentString}`;
expect(userSync.length).to.be.equal(1);
expect(userSync[0].type).to.be.equal('iframe');
expect(userSync[0].url).to.be.equal(expectedUrl);
Expand Down