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

MgidX Bid Adapter: add optional region param #10612

Merged
merged 10 commits into from
Jan 30, 2024
13 changes: 11 additions & 2 deletions modules/mgidXBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { USERSYNC_DEFAULT_CONFIG } from '../src/userSync.js';

const BIDDER_CODE = 'mgidX';
const GVLID = 358;
const AD_URL = 'https://us-east-x.mgid.com/pbjs';
const AD_URL = 'https://#{REGION}#.mgid.com/pbjs';
const PIXEL_SYNC_URL = 'https://cm.mgid.com/i.gif';
const IFRAME_SYNC_URL = 'https://cm.mgid.com/i.html';

Expand Down Expand Up @@ -181,9 +181,18 @@ export const spec = {
placements.push(getPlacementReqData(bid));
}

const region = validBidRequests[0].params?.region;

let url;
if (region === 'eu') {
url = AD_URL.replace('#{REGION}#', 'eu');
} else {
url = AD_URL.replace('#{REGION}#', 'us-east-x');
}

return {
method: 'POST',
url: AD_URL,
url: url,
data: request
};
},
Expand Down
21 changes: 12 additions & 9 deletions test/spec/modules/mgidXBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { config } from '../../../src/config';
import { USERSYNC_DEFAULT_CONFIG } from '../../../src/userSync';

const bidder = 'mgidX'
const adUrl = 'https://us-east-x.mgid.com/pbjs';

describe('MGIDXBidAdapter', function () {
const bids = [
Expand All @@ -19,6 +18,7 @@ describe('MGIDXBidAdapter', function () {
}
},
params: {
region: 'eu',
placementId: 'testBanner',
}
},
Expand Down Expand Up @@ -56,6 +56,7 @@ describe('MGIDXBidAdapter', function () {
}
},
params: {
region: 'eu',
placementId: 'testNative',
}
}
Expand Down Expand Up @@ -108,8 +109,16 @@ describe('MGIDXBidAdapter', function () {
expect(serverRequest.method).to.equal('POST');
});

it('Returns valid URL', function () {
expect(serverRequest.url).to.equal(adUrl);
it('Returns valid EU URL', function () {
bids[0].params.region = 'eu';
serverRequest = spec.buildRequests(bids, bidderRequest);
expect(serverRequest.url).to.equal('https://eu.mgid.com/pbjs');
});

it('Returns valid EAST URL', function () {
bids[0].params.region = 'other';
serverRequest = spec.buildRequests(bids, bidderRequest);
expect(serverRequest.url).to.equal('https://us-east-x.mgid.com/pbjs');
});

it('Returns general data valid', function () {
Expand Down Expand Up @@ -193,12 +202,6 @@ describe('MGIDXBidAdapter', function () {
expect(data.ccpa).to.equal(bidderRequest.uspConsent);
expect(data.gdpr).to.not.exist;
});

it('Returns empty data if no valid requests are passed', function () {
serverRequest = spec.buildRequests([], bidderRequest);
let data = serverRequest.data;
expect(data.placements).to.be.an('array').that.is.empty;
});
});

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