Skip to content
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

nextMillenniumBidAdapter: improve getUserSyncs function #9313

Merged
merged 17 commits into from
Dec 14, 2022
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
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