Skip to content

Commit

Permalink
add first-party data support to beachfront adapter (#7733)
Browse files Browse the repository at this point in the history
Co-authored-by: John Salis <john@beachfront.com>
  • Loading branch information
jsalis and John Salis authored Nov 18, 2021
1 parent 3958012 commit 29bf57d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 18 deletions.
31 changes: 14 additions & 17 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { logWarn, deepAccess, isArray, parseSizesInput, isFn, parseUrl, getUniqueIdentifierStr } from '../src/utils.js';
import { logWarn, deepAccess, deepSetValue, deepClone, isArray, parseSizesInput, isFn, parseUrl, getUniqueIdentifierStr } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
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.18';
const ADAPTER_VERSION = '1.19';
const ADAPTER_NAME = 'BFIO_PREBID';
const OUTSTREAM = 'outstream';
const CURRENCY = 'USD';
Expand Down Expand Up @@ -360,6 +360,7 @@ function createVideoRequestData(bid, bidderRequest) {
let tagid = getVideoBidParam(bid, 'tagid');
let topLocation = getTopWindowLocation(bidderRequest);
let eids = getEids(bid);
let ortb2 = deepClone(config.getConfig('ortb2'));
let payload = {
isPrebid: true,
appId: appId,
Expand All @@ -378,6 +379,7 @@ function createVideoRequestData(bid, bidderRequest) {
displaymanagerver: ADAPTER_VERSION
}],
site: {
...deepAccess(ortb2, 'site', {}),
page: topLocation.href,
domain: topLocation.hostname
},
Expand All @@ -389,39 +391,32 @@ function createVideoRequestData(bid, bidderRequest) {
js: 1,
geo: {}
},
regs: {
ext: {}
},
source: {
ext: {}
},
user: {
ext: {}
},
app: deepAccess(ortb2, 'app'),
user: deepAccess(ortb2, 'user'),
cur: [CURRENCY]
};

if (bidderRequest && bidderRequest.uspConsent) {
payload.regs.ext.us_privacy = bidderRequest.uspConsent;
deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

if (bidderRequest && bidderRequest.gdprConsent) {
let { gdprApplies, consentString } = bidderRequest.gdprConsent;
payload.regs.ext.gdpr = gdprApplies ? 1 : 0;
payload.user.ext.consent = consentString;
deepSetValue(payload, 'regs.ext.gdpr', gdprApplies ? 1 : 0);
deepSetValue(payload, 'user.ext.consent', consentString);
}

if (bid.schain) {
payload.source.ext.schain = bid.schain;
deepSetValue(payload, 'source.ext.schain', bid.schain);
}

if (eids.length > 0) {
payload.user.ext.eids = eids;
deepSetValue(payload, 'user.ext.eids', eids);
}

let connection = navigator.connection || navigator.webkitConnection;
if (connection && connection.effectiveType) {
payload.device.connectiontype = connection.effectiveType;
deepSetValue(payload, 'device.connectiontype', connection.effectiveType);
}

return payload;
Expand All @@ -439,8 +434,10 @@ function createBannerRequestData(bids, bidderRequest) {
sizes: getBannerSizes(bid)
};
});
let ortb2 = deepClone(config.getConfig('ortb2'));
let payload = {
slots: slots,
ortb2: ortb2,
page: topLocation.href,
domain: topLocation.hostname,
search: topLocation.search,
Expand Down
66 changes: 65 additions & 1 deletion test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, OUTSTREAM_SRC, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter.js';
import { parseUrl } from 'src/utils.js';
import { config } from 'src/config.js';
import { parseUrl, deepAccess } from 'src/utils.js';

describe('BeachfrontAdapter', function () {
let bidRequests;
Expand Down Expand Up @@ -556,6 +557,69 @@ describe('BeachfrontAdapter', function () {
});
});

describe('with first-party data', function () {
let sandbox

beforeEach(function () {
sandbox = sinon.sandbox.create();
});

afterEach(function () {
sandbox.restore();
});

it('must add first-party data to the video bid request', function () {
sandbox.stub(config, 'getConfig').callsFake(key => {
const cfg = {
ortb2: {
site: {
keywords: 'test keyword'
},
user: {
data: 'some user data'
}
}
};
return deepAccess(cfg, key);
});
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { video: {} };
const bidderRequest = {
refererInfo: {
referer: 'http://example.com/page.html'
}
};
const requests = spec.buildRequests([ bidRequest ], bidderRequest);
const data = requests[0].data;
expect(data.user.data).to.equal('some user data');
expect(data.site.keywords).to.equal('test keyword');
expect(data.site.page).to.equal('http://example.com/page.html');
expect(data.site.domain).to.equal('example.com');
});

it('must add first-party data to the banner bid request', function () {
sandbox.stub(config, 'getConfig').callsFake(key => {
const cfg = {
ortb2: {
site: {
keywords: 'test keyword'
},
user: {
data: 'some user data'
}
}
};
return deepAccess(cfg, key);
});
const bidRequest = bidRequests[0];
bidRequest.mediaTypes = { banner: {} };
const requests = spec.buildRequests([ bidRequest ]);
const data = requests[0].data;
expect(data.ortb2.user.data).to.equal('some user data');
expect(data.ortb2.site.keywords).to.equal('test keyword');
});
});

describe('for multi-format bids', function () {
it('should create a POST request for each bid format', function () {
const width = 300;
Expand Down

0 comments on commit 29bf57d

Please sign in to comment.