Skip to content

Commit

Permalink
nextMillenniumBidAdapter: improve getUserSyncs function (prebid#9313)
Browse files Browse the repository at this point in the history
* add video support

* improve userSync url

* improve userSync url

* Add tests for a new cases

* use deepAccess instead of instanceof
  • Loading branch information
mifanich authored and JacobKlein26 committed Feb 8, 2023
1 parent 7d5f870 commit 6e6fff3
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 49 deletions.
45 changes: 32 additions & 13 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
isArray,
_each,
createTrackPixelHtml,
deepAccess,
Expand All @@ -24,7 +25,6 @@ const BIDDER_CODE = 'nextMillennium';
const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction';
const TEST_ENDPOINT = 'https://test.pbs.nextmillmedia.com/openrtb2/auction';
const REPORT_ENDPOINT = 'https://report2.hb.brainlyads.com/statistics/metric';
const SYNC_ENDPOINT = 'https://cookies.nextmillmedia.com/sync?';
const TIME_TO_LIVE = 360;
const VIDEO_PARAMS = [
'api', 'linearity', 'maxduration', 'mimes', 'minduration', 'placement',
Expand Down Expand Up @@ -208,20 +208,27 @@ export const spec = {

getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
const pixels = [];
let syncUrl = SYNC_ENDPOINT;

if (gdprConsent && gdprConsent.gdprApplies) {
syncUrl += 'gdpr=1&gdpr_consent=' + gdprConsent.consentString;
}
if (uspConsent) {
syncUrl += 'us_privacy=' + uspConsent;
}
if (isArray(responses)) {
responses.forEach(response => {
if (syncOptions.pixelEnabled) {
deepAccess(response, 'body.ext.sync.image', []).forEach(imgUrl => {
pixels.push({
type: 'image',
url: replaceUsersyncMacros(imgUrl, gdprConsent, uspConsent)
});
})
}

if (syncOptions.iframeEnabled) {
pixels.push({type: 'iframe', url: syncUrl + 'type=iframe'});
}
if (syncOptions.pixelEnabled) {
pixels.push({type: 'image', url: syncUrl + 'type=image'});
if (syncOptions.iframeEnabled) {
deepAccess(response, 'body.ext.sync.iframe', []).forEach(iframeUrl => {
pixels.push({
type: 'iframe',
url: replaceUsersyncMacros(iframeUrl, gdprConsent, uspConsent)
});
})
}
})
}

return pixels;
Expand Down Expand Up @@ -263,6 +270,18 @@ export const spec = {
},
};

function replaceUsersyncMacros(url, gdprConsent, uspConsent) {
const { consentString, gdprApplies } = gdprConsent;

return url.replace(
'{{.GDPR}}', Number(gdprApplies)
).replace(
'{{.GDPRConsent}}', consentString
).replace(
'{{.USPrivacy}}', uspConsent
);
};

function getAdEl(bid) {
// best way I could think of to get El, is by matching adUnitCode to google slots...
const slot = window.googletag && window.googletag.pubads && window.googletag.pubads().getSlots().find(slot => slot.getAdUnitPath() === bid.adUnitCode);
Expand Down
83 changes: 47 additions & 36 deletions test/spec/modules/nextMillenniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ describe('nextMillenniumBidAdapterTests', function() {
}
];

const serverResponse = {
body: {
id: 'f7b3d2da-e762-410c-b069-424f92c4c4b2',
seatbid: [
{
bid: [
{
id: '7457329903666272789',
price: 0.5,
adm: 'Hello! It\'s a test ad!',
adid: '96846035',
adomain: ['test.addomain.com'],
w: 300,
h: 250
}
]
}
],
cur: 'USD',
ext: {
sync: {
image: ['urlA'],
iframe: ['urlB'],
}
}
}
};

const bidRequestDataGI = [
{
adUnitCode: 'test-banner-gi',
Expand Down Expand Up @@ -96,6 +124,24 @@ describe('nextMillenniumBidAdapterTests', function() {
expect(JSON.parse(request[0].data).regs.ext.gdpr).to.equal(1);
});

it('Test getUserSyncs function', function () {
const syncOptions = {
'iframeEnabled': false,
'pixelEnabled': true
}
let userSync = spec.getUserSyncs(syncOptions, [serverResponse], bidRequestData[0].gdprConsent, bidRequestData[0].uspConsent);
expect(userSync).to.be.an('array').with.lengthOf(1);
expect(userSync[0].type).to.equal('image');
expect(userSync[0].url).to.equal('urlA');

syncOptions.iframeEnabled = true;
syncOptions.pixelEnabled = false;
userSync = spec.getUserSyncs(syncOptions, [serverResponse], bidRequestData[0].gdprConsent, bidRequestData[0].uspConsent);
expect(userSync).to.be.an('array').with.lengthOf(1);
expect(userSync[0].type).to.equal('iframe');
expect(userSync[0].url).to.equal('urlB');
});

it('Request params check without GDPR Consent', function () {
delete bidRequestData[0].gdprConsent
const request = spec.buildRequests(bidRequestData, bidRequestData[0]);
Expand Down Expand Up @@ -137,51 +183,16 @@ describe('nextMillenniumBidAdapterTests', function() {
it('Check if imp object was added', function() {
const request = spec.buildRequests(bidRequestData)
expect(JSON.parse(request[0].data).imp).to.be.an('array')
})
});

it('Check if imp prebid stored id is correct', function() {
const request = spec.buildRequests(bidRequestData)
const requestData = JSON.parse(request[0].data);
const storedReqId = requestData.ext.prebid.storedrequest.id;
expect(requestData.imp[0].ext.prebid.storedrequest.id).to.equal(storedReqId)
})

it('Test getUserSyncs function', function () {
const syncOptions = {
'iframeEnabled': false,
'pixelEnabled': true
}
const userSync = spec.getUserSyncs(syncOptions);
expect(userSync).to.be.an('array').with.lengthOf(1);
expect(userSync[0].type).to.exist;
expect(userSync[0].url).to.exist;
expect(userSync[0].type).to.be.equal('image');
expect(userSync[0].url).to.be.equal('https://cookies.nextmillmedia.com/sync?type=image');
});

it('validate_response_params', function() {
const serverResponse = {
body: {
id: 'f7b3d2da-e762-410c-b069-424f92c4c4b2',
seatbid: [
{
bid: [
{
id: '7457329903666272789',
price: 0.5,
adm: 'Hello! It\'s a test ad!',
adid: '96846035',
adomain: ['test.addomain.com'],
w: 300,
h: 250
}
]
}
],
cur: 'USD'
}
};

let bids = spec.interpretResponse(serverResponse, bidRequestData[0]);
expect(bids).to.have.lengthOf(1);

Expand Down

0 comments on commit 6e6fff3

Please sign in to comment.