Skip to content

Commit

Permalink
sharedID support added
Browse files Browse the repository at this point in the history
  • Loading branch information
ym-abaranov committed Sep 27, 2021
1 parent f4f634d commit 8abe4df
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
20 changes: 19 additions & 1 deletion modules/yieldmoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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}?${utils.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 @@ -595,3 +602,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 (utils.deepAccess(bidRequest, 'userId')) {
return createEidsArray(bidRequest.userId) || [];
}
};
32 changes: 30 additions & 2 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 @@ -482,6 +496,20 @@ describe('YieldmoAdapter', function () {
};
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

0 comments on commit 8abe4df

Please sign in to comment.