Skip to content

Commit

Permalink
Improve Digital bid adapter: added support for cat and genre (prebid#…
Browse files Browse the repository at this point in the history
…7899)

* Feature Prebid First Party Data (#2)

* HBT-166: Added PageCategory and Genre to request object from First-Party-Data

* HBT-166: Added PageCategory and Genre to request object from First-Party-Data and Rewrite Test Cases

* Update improvedigitalBidAdapter.js

Version increased

Co-authored-by: Faisal Islam <93644923+faisalvs@users.noreply.github.com>
  • Loading branch information
jbartek25 and faisalvs authored Jan 3, 2022
1 parent 5311e17 commit b3fd85e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
26 changes: 24 additions & 2 deletions 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 All @@ -11,7 +11,7 @@ const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js
const VIDEO_TARGETING = ['skip', 'skipmin', 'skipafter'];

export const spec = {
version: '7.5.0',
version: '7.6.0',
code: BIDDER_CODE,
gvlid: 253,
aliases: ['id'],
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

0 comments on commit b3fd85e

Please sign in to comment.