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

Beachfront Bid Adapter: add first-party data support #7733

Merged
merged 1 commit into from
Nov 18, 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
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