Skip to content

Commit

Permalink
MGIDX Adapter: Update (prebid#11728)
Browse files Browse the repository at this point in the history
* new adapter - MgidX

* add new required param host

* rem host, add region

* MGIDX Adapter: update

---------

Co-authored-by: Evgeny Nagorny <evjman@gmail.com>
Co-authored-by: xmgiddev <>
  • Loading branch information
2 people authored and DecayConstant committed Jul 18, 2024
1 parent d0ec110 commit 91fbb18
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 15 deletions.
34 changes: 25 additions & 9 deletions modules/mgidXBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
isFn,
deepAccess,
logMessage,
logError,
Expand Down Expand Up @@ -39,7 +38,7 @@ function isBidResponseValid(bid) {
}

function getPlacementReqData(bid) {
const { params, bidId, mediaTypes } = bid;
const { params, bidId, mediaTypes, transactionId, userIdAsEids } = bid;
const schain = bid.schain || {};
const { placementId, endpointId } = params;
const bidfloor = getBidFloor(bid);
Expand Down Expand Up @@ -69,7 +68,7 @@ function getPlacementReqData(bid) {
placement.mimes = mediaTypes[VIDEO].mimes;
placement.protocols = mediaTypes[VIDEO].protocols;
placement.startdelay = mediaTypes[VIDEO].startdelay;
placement.placement = mediaTypes[VIDEO].placement;
placement.plcmt = mediaTypes[VIDEO].plcmt;
placement.skip = mediaTypes[VIDEO].skip;
placement.skipafter = mediaTypes[VIDEO].skipafter;
placement.minbitrate = mediaTypes[VIDEO].minbitrate;
Expand All @@ -83,14 +82,19 @@ function getPlacementReqData(bid) {
placement.adFormat = NATIVE;
}

if (transactionId) {
placement.ext = placement.ext || {};
placement.ext.tid = transactionId;
}

if (userIdAsEids && userIdAsEids.length) {
placement.eids = userIdAsEids;
}

return placement;
}

function getBidFloor(bid) {
if (!isFn(bid.getFloor)) {
return deepAccess(bid, 'params.bidfloor', 0);
}

try {
const bidFloor = bid.getFloor({
currency: 'USD',
Expand Down Expand Up @@ -150,6 +154,7 @@ export const spec = {
} catch (e) {
logMessage(e);
}

let location = refferLocation || winLocation;
const language = (navigator && navigator.language) ? navigator.language.split('-')[0] : '';
const host = location.host;
Expand All @@ -164,17 +169,28 @@ export const spec = {
host,
page,
placements,
coppa: config.getConfig('coppa') === true ? 1 : 0,
ccpa: bidderRequest.uspConsent || undefined,
coppa: deepAccess(bidderRequest, 'ortb2.regs.coppa') ? 1 : 0,
tmax: bidderRequest.timeout
};

if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}

if (bidderRequest.gdprConsent) {
request.gdpr = {
consentString: bidderRequest.gdprConsent.consentString
};
}

if (bidderRequest.gppConsent) {
request.gpp = bidderRequest.gppConsent.gppString;
request.gpp_sid = bidderRequest.gppConsent.applicableSections;
} else if (bidderRequest.ortb2?.regs?.gpp) {
request.gpp = bidderRequest.ortb2.regs.gpp;
request.gpp_sid = bidderRequest.ortb2.regs.gpp_sid;
}

const len = validBidRequests.length;
for (let i = 0; i < len; i++) {
const bid = validBidRequests[i];
Expand Down
107 changes: 101 additions & 6 deletions test/spec/modules/mgidXBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import { USERSYNC_DEFAULT_CONFIG } from '../../../src/userSync';
const bidder = 'mgidX'

describe('MGIDXBidAdapter', function () {
const userIdAsEids = [{
source: 'test.org',
uids: [{
id: '01**********',
atype: 1,
ext: {
third: '01***********'
}
}]
}];
const bids = [
{
bidId: getUniqueIdentifierStr(),
Expand All @@ -19,8 +29,9 @@ describe('MGIDXBidAdapter', function () {
},
params: {
region: 'eu',
placementId: 'testBanner',
}
placementId: 'testBanner'
},
userIdAsEids
},
{
bidId: getUniqueIdentifierStr(),
Expand All @@ -33,8 +44,9 @@ describe('MGIDXBidAdapter', function () {
}
},
params: {
placementId: 'testVideo',
}
placementId: 'testVideo'
},
userIdAsEids
},
{
bidId: getUniqueIdentifierStr(),
Expand All @@ -57,8 +69,9 @@ describe('MGIDXBidAdapter', function () {
},
params: {
region: 'eu',
placementId: 'testNative',
}
placementId: 'testNative'
},
userIdAsEids
}
];

Expand Down Expand Up @@ -160,6 +173,56 @@ describe('MGIDXBidAdapter', function () {
expect(placement.schain).to.be.an('object');
expect(placement.bidfloor).to.exist.and.to.equal(0);
expect(placement.type).to.exist.and.to.equal('publisher');
expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids);

if (placement.adFormat === BANNER) {
expect(placement.sizes).to.be.an('array');
}
switch (placement.adFormat) {
case BANNER:
expect(placement.sizes).to.be.an('array');
break;
case VIDEO:
expect(placement.playerSize).to.be.an('array');
expect(placement.minduration).to.be.an('number');
expect(placement.maxduration).to.be.an('number');
break;
case NATIVE:
expect(placement.native).to.be.an('object');
break;
}
}
});

it('Returns valid endpoints', function () {
const bids = [
{
bidId: getUniqueIdentifierStr(),
bidder: bidder,
mediaTypes: {
[BANNER]: {
sizes: [[300, 250]]
}
},
params: {
endpointId: 'testBanner',
},
userIdAsEids
}
];

let serverRequest = spec.buildRequests(bids, bidderRequest);

const { placements } = serverRequest.data;
for (let i = 0, len = placements.length; i < len; i++) {
const placement = placements[i];
expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']);
expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]);
expect(placement.bidId).to.be.a('string');
expect(placement.schain).to.be.an('object');
expect(placement.bidfloor).to.exist.and.to.equal(0);
expect(placement.type).to.exist.and.to.equal('network');
expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids);

if (placement.adFormat === BANNER) {
expect(placement.sizes).to.be.an('array');
Expand Down Expand Up @@ -205,6 +268,38 @@ describe('MGIDXBidAdapter', function () {
});
});

describe('gpp consent', function () {
it('bidderRequest.gppConsent', () => {
bidderRequest.gppConsent = {
gppString: 'abc123',
applicableSections: [8]
};

let serverRequest = spec.buildRequests(bids, bidderRequest);
let data = serverRequest.data;
expect(data).to.be.an('object');
expect(data).to.have.property('gpp');
expect(data).to.have.property('gpp_sid');

delete bidderRequest.gppConsent;
})

it('bidderRequest.ortb2.regs.gpp', () => {
bidderRequest.ortb2 = bidderRequest.ortb2 || {};
bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {};
bidderRequest.ortb2.regs.gpp = 'abc123';
bidderRequest.ortb2.regs.gpp_sid = [8];

let serverRequest = spec.buildRequests(bids, bidderRequest);
let data = serverRequest.data;
expect(data).to.be.an('object');
expect(data).to.have.property('gpp');
expect(data).to.have.property('gpp_sid');

bidderRequest.ortb2;
})
});

describe('interpretResponse', function () {
it('Should interpret banner response', function () {
const banner = {
Expand Down

0 comments on commit 91fbb18

Please sign in to comment.