Skip to content

Commit

Permalink
Add IdentityLink support to Beachfront adapter (#5977)
Browse files Browse the repository at this point in the history
* add IdentityLink support to beachfront adapter

* bump adapter version

Co-authored-by: John Salis <[email protected]>
  • Loading branch information
jsalis and John Salis authored Nov 17, 2020
1 parent fe7acf8 commit f6e3465
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
52 changes: 38 additions & 14 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js';
import find from 'core-js-pure/features/array/find.js';
import includes from 'core-js-pure/features/array/includes.js';

const ADAPTER_VERSION = '1.12';
const ADAPTER_VERSION = '1.13';
const ADAPTER_NAME = 'BFIO_PREBID';
const OUTSTREAM = 'outstream';

Expand All @@ -17,6 +17,11 @@ export const OUTSTREAM_SRC = 'https://player-cdn.beachfrontmedia.com/playerapi/l
export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration', 'placement', 'skip', 'skipmin', 'skipafter'];
export const DEFAULT_MIMES = ['video/mp4', 'application/javascript'];

export const SUPPORTED_USER_IDS = [
{ key: 'tdid', source: 'adserver.org', rtiPartner: 'TDID', queryParam: 'tdid' },
{ key: 'idl_env', source: 'liveramp.com', rtiPartner: 'idl', queryParam: 'idl' }
];

let appId = '';

export const spec = {
Expand Down Expand Up @@ -257,6 +262,29 @@ function getTopWindowReferrer() {
}
}

function getEids(bid) {
return SUPPORTED_USER_IDS
.map(getUserId(bid))
.filter(x => x);
}

function getUserId(bid) {
return ({ key, source, rtiPartner }) => {
let id = bid.userId && bid.userId[key];
return id ? formatEid(id, source, rtiPartner) : null;
};
}

function formatEid(id, source, rtiPartner) {
return {
source,
uids: [{
id,
ext: { rtiPartner }
}]
};
}

function getVideoTargetingParams(bid) {
const result = {};
const excludeProps = ['playerSize', 'context', 'w', 'h'];
Expand All @@ -281,6 +309,7 @@ function createVideoRequestData(bid, bidderRequest) {
let bidfloor = getVideoBidParam(bid, 'bidfloor');
let tagid = getVideoBidParam(bid, 'tagid');
let topLocation = getTopWindowLocation(bidderRequest);
let eids = getEids(bid);
let payload = {
isPrebid: true,
appId: appId,
Expand Down Expand Up @@ -329,16 +358,8 @@ function createVideoRequestData(bid, bidderRequest) {
payload.user.ext.consent = consentString;
}

if (bid.userId && bid.userId.tdid) {
payload.user.ext.eids = [{
source: 'adserver.org',
uids: [{
id: bid.userId.tdid,
ext: {
rtiPartner: 'TDID'
}
}]
}];
if (eids.length > 0) {
payload.user.ext.eids = eids;
}

let connection = navigator.connection || navigator.webkitConnection;
Expand Down Expand Up @@ -385,9 +406,12 @@ function createBannerRequestData(bids, bidderRequest) {
payload.gdprConsent = consentString;
}

if (bids[0] && bids[0].userId && bids[0].userId.tdid) {
payload.tdid = bids[0].userId.tdid;
}
SUPPORTED_USER_IDS.forEach(({ key, queryParam }) => {
let id = bids[0] && bids[0].userId && bids[0].userId[key];
if (id) {
payload[queryParam] = id;
}
});

return payload;
}
Expand Down
28 changes: 28 additions & 0 deletions test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ describe('BeachfrontAdapter', function () {
}]
});
});

it('must add the IdentityLink ID to the request', () => {
const idl_env = '4321';
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
bidRequest.userId = { idl_env };
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.user.ext.eids[0]).to.deep.equal({
source: 'liveramp.com',
uids: [{
id: idl_env,
ext: {
rtiPartner: 'idl'
}
}]
});
});
});

describe('for banner bids', function () {
Expand Down Expand Up @@ -435,6 +453,16 @@ describe('BeachfrontAdapter', function () {
const data = requests[0].data;
expect(data.tdid).to.equal(tdid);
});

it('must add the IdentityLink ID to the request', () => {
const idl_env = '4321';
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { banner: {} };
bidRequest.userId = { idl_env };
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.idl).to.equal(idl_env);
});
});

describe('for multi-format bids', function () {
Expand Down

0 comments on commit f6e3465

Please sign in to comment.