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

Yieldmo Bid Adapter: add shared id support and cleaned up device.ip #7501

Merged
merged 3 commits into from
Sep 29, 2021
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
26 changes: 20 additions & 6 deletions modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { getWindowTop, deepAccess, parseQueryStringParameters, isArrayOfNums, isArray, parseUrl, isEmpty, deepSetValue, isStr, isNumber, isInteger, isBoolean, logError } from '../src/utils.js';
import { isNumber, isStr, isInteger, isBoolean, isArray, isEmpty, isArrayOfNums, getWindowTop, parseQueryStringParameters, parseUrl, deepSetValue, deepAccess, logError } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
import includes from 'core-js-pure/features/array/includes';
import find from 'core-js-pure/features/array/find.js';
import { createEidsArray } from './userId/eids.js';

const BIDDER_CODE = 'yieldmo';
const CURRENCY = 'USD';
Expand Down Expand Up @@ -46,8 +47,8 @@ export const spec = {
buildRequests: function (bidRequests, bidderRequest) {
const bannerBidRequests = bidRequests.filter(request => hasBannerMediaType(request));
const videoBidRequests = bidRequests.filter(request => hasVideoMediaType(request));

let serverRequests = [];
const eids = getEids(bidRequests[0]) || [];
if (bannerBidRequests.length > 0) {
let serverRequest = {
pbav: '$prebid.version$',
Expand Down Expand Up @@ -99,6 +100,9 @@ export const spec = {
});
serverRequest.p = '[' + serverRequest.p.toString() + ']';

if (eids.length) {
serverRequest.eids = JSON.stringify(eids);
};
// check if url exceeded max length
const url = `${BANNER_SERVER_ENDPOINT}?${parseQueryStringParameters(serverRequest)}`;
let extraCharacters = url.length - MAX_BANNER_REQUEST_URL_LENGTH;
Expand All @@ -121,6 +125,9 @@ export const spec = {

if (videoBidRequests.length > 0) {
const serverRequest = openRtbRequest(videoBidRequests, bidderRequest);
if (eids.length) {
serverRequest.user = { eids };
};
serverRequests.push({
method: 'POST',
url: VIDEO_SERVER_ENDPOINT,
Expand Down Expand Up @@ -447,14 +454,10 @@ function openRtbSite(bidRequest, bidderRequest) {
* @return Object OpenRTB's 'device' object
*/
function openRtbDevice(bidRequest) {
const ip = deepAccess(bidRequest, 'params.device.ip');
const deviceObj = {
ua: navigator.userAgent,
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage),
};
if (ip) {
deviceObj.ip = ip;
}
return deviceObj;
}

Expand Down Expand Up @@ -595,3 +598,14 @@ function shortcutProperty(extraCharacters, target, propertyName) {

return charactersLeft;
}

/**
* Creates and returnes eids arr using createEidsArray from './userId/eids.js' module;
* @param {Object} openRtbRequest OpenRTB's request as a cource of userId.
* @return array of eids objects
*/
function getEids(bidRequest) {
if (deepAccess(bidRequest, 'userId')) {
return createEidsArray(bidRequest.userId) || [];
}
};
39 changes: 30 additions & 9 deletions test/spec/modules/yieldmoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('YieldmoAdapter', function () {
});

it('should only shortcut properties rather then completely remove it', () => {
const longString = new Array(7516).join('a');
const longString = new Array(8000).join('a');
const localWindow = utils.getWindowTop();

const originalTitle = localWindow.document.title;
Expand All @@ -319,7 +319,7 @@ describe('YieldmoAdapter', function () {
refererInfo: {
numIframes: 1,
reachedTop: true,
referer: longString,
title: longString,
},
})
)[0];
Expand All @@ -345,6 +345,20 @@ describe('YieldmoAdapter', function () {
let placementInfo = buildAndGetPlacementInfo(bidArray);
expect(placementInfo).to.include('"gpid":"/6355419/Travel/Europe/France/Paris"');
});

it('should add eids to the banner bid request', function () {
const params = {
userId: {pubcid: 'fake_pubcid'},
fakeUserIdAsEids: [{
source: 'pubcid.org',
uids: [{
id: 'fake_pubcid',
atype: 1
}]
}]
};
expect(buildAndGetData([mockBannerBid({...params})]).eids).equal(JSON.stringify(params.fakeUserIdAsEids));
});
});

describe('Instream video:', function () {
Expand Down Expand Up @@ -469,19 +483,26 @@ describe('YieldmoAdapter', function () {
expect(buildAndGetData([mockVideoBid({schain})]).schain).to.deep.equal(schain);
});

it('should add ip to the video bidRequest', () => {
const device = {
ip: '111.222.333.444'
};
expect(buildAndGetData([mockVideoBid(null, {device})]).device.ip).to.be.equal(device.ip);
});

it('should add gpid to the video request', function () {
const ortb2Imp = {
ext: { data: { pbadslot: '/6355419/Travel/Europe/France/Paris' } },
};
expect(buildAndGetData([mockVideoBid({ortb2Imp})]).imp[0].ext.gpid).to.be.equal(ortb2Imp.ext.data.pbadslot);
});

it('should add eids to the video bid request', function () {
const params = {
userId: {pubcid: 'fake_pubcid'},
fakeUserIdAsEids: [{
source: 'pubcid.org',
uids: [{
id: 'fake_pubcid',
atype: 1
}]
}]
};
expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids);
});
});
});

Expand Down