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

Feature Prebid First Party Data #2

Merged
merged 4 commits into from
Dec 30, 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
24 changes: 23 additions & 1 deletion modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepSetValue, logError, _each, getBidRequest, isNumber, isArray, deepAccess, isFn, isPlainObject, logWarn, getBidIdParameter, getUniqueIdentifierStr, isEmpty, isInteger } from '../src/utils.js';
import { deepSetValue, logError, _each, getBidRequest, isNumber, isArray, deepAccess, isFn, isPlainObject, logWarn, getBidIdParameter, getUniqueIdentifierStr, isEmpty, isInteger, isStr } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
Expand Down Expand Up @@ -73,6 +73,22 @@ export const spec = {
requestParameters.referrer = bidderRequest.refererInfo.referer;
}

// Adding first party data
const site = config.getConfig('ortb2.site');
if (site) {
const pageCategory = site.pagecat || site.cat;
if (pageCategory && isArray(pageCategory)) {
requestParameters.pagecat = pageCategory.filter((category) => {
return category && isStr(category)
});
}
const genre = deepAccess(site, 'content.genre');
if (genre && isStr(genre)) {
requestParameters.genre = genre;
}
}
// End of adding first party data

requestParameters.schain = bidRequests[0].schain;

if (bidRequests[0].userId) {
Expand Down Expand Up @@ -621,6 +637,12 @@ export function ImproveDigitalAdServerJSClient(endPoint) {
if (requestParameters.schain) {
impressionBidRequestObject.schain = requestParameters.schain;
}
if (requestParameters.pagecat) {
impressionBidRequestObject.pagecat = requestParameters.pagecat;
}
if (requestParameters.genre) {
impressionBidRequestObject.genre = requestParameters.genre;
}
if (requestParameters.user) {
impressionBidRequestObject.user = requestParameters.user;
}
Expand Down
42 changes: 42 additions & 0 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,48 @@ describe('Improve Digital Adapter Tests', function () {
});
getConfigStub.restore();
});

it('should set pagecat and genre ➞ fpd:ortb2.site', function() {
config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2"],"pagecat":["IAB2-2"],"content":{"genre":"Adventure"}}}}'));
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0];
const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
expect(params.bid_request.pagecat).to.be.an('array');
expect(params.bid_request.pagecat).to.deep.equal(['IAB2-2']);
expect(params.bid_request.genre).to.be.a('string');
expect(params.bid_request.genre).be.equal('Adventure');
});

it('should not set pagecat and genre when malformed data provided ➞ fpd:ortb2.site', function() {
config.setConfig(JSON.parse('{"ortb2":{"site":{"pagecat":"IAB2-2","content":{"genre":["Adventure"]}}}}'));
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0];
const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
expect(params.bid_request.pagecat).does.not.exist;
expect(params.bid_request.genre).does.not.exist;
});

it('should use cat when pagecat not available ➞ fpd:ortb2.site', function() {
config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2"]}}}'));
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0];
const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
expect(params.bid_request.pagecat).to.be.an('array');
expect(params.bid_request.pagecat).to.deep.equal(['IAB2']);
});

it('should format pagecat correctly ➞ fpd:ortb2.site', function() {
config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2", ["IAB-1"], "IAB3", 123, ""]}}}'));
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0];
const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length)));
expect(params.bid_request.pagecat).to.be.an('array');
expect(params.bid_request.pagecat).to.deep.equal([
'IAB2',
'IAB3'
]
);
});
});

const serverResponse = {
Expand Down