From 9d06a8bc8fa7bdad27134915c005a333e02f27c3 Mon Sep 17 00:00:00 2001 From: Faisal Islam Date: Thu, 2 Dec 2021 17:16:45 +0600 Subject: [PATCH 1/2] HBT-166: Added PageCategory and Genre to request object from First-Party-Data --- modules/improvedigitalBidAdapter.js | 18 +++++++++- .../modules/improvedigitalBidAdapter_spec.js | 34 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 688a8815e93..0dd36155199 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -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'; @@ -57,6 +57,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) { diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index 095e50f0c66..0793d557928 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -513,6 +513,40 @@ describe('Improve Digital Adapter Tests', function () { }); getConfigStub.restore(); }); + + it('should set pagecat and genre ➞ fpd:ortb2.site', function() { + const bidRequest = Object.assign({}, simpleBidRequest); + config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2"],"pagecat":["IAB2-2"],"content":{"genre":"Adventure"}}}}')); + const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0]; + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); + expect(params.bid_request.pagecat).is('array').equal(['IAB2-2']) + expect(params.bid_request.genre, 'Adventure'); + }); + + it('should not set pagecat and genre when malformed data provided ➞ fpd:ortb2.site', function() { + const bidRequest = Object.assign({}, simpleBidRequest); + config.setConfig(JSON.parse('{"ortb2":{"site":{"pagecat":"IAB2-2","content":{"genre":["Adventure"]}}}}')); + 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() { + const bidRequest = Object.assign({}, simpleBidRequest); + config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2"]}}}')); + const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0]; + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); + expect(params.bid_request.pagecat).is('array').equal(['IAB2']); + }); + + it('should format pagecat correctly ➞ fpd:ortb2.site', function() { + const bidRequest = Object.assign({}, simpleBidRequest); + config.setConfig(JSON.parse('{"ortb2":{"site":{"cat":["IAB2", ["IAB-1"], "IAB3", 123, ""]}}}')); + const request = spec.buildRequests([bidRequest], bidderRequestReferrer)[0]; + const params = JSON.parse(decodeURIComponent(request.data.substring(PARAM_PREFIX.length))); + expect(params.bid_request.pagecat).is('array').equal(['IAB2', 'IAB3']); + }); }); const serverResponse = { From dbc692e01d6910424f46163d6496a522295dd2d8 Mon Sep 17 00:00:00 2001 From: Faisal Islam Date: Mon, 20 Dec 2021 14:27:38 +0600 Subject: [PATCH 2/2] HBT-166: Added PageCategory and Genre to request object from First-Party-Data and Rewrite Test Cases --- modules/improvedigitalBidAdapter.js | 6 +++++ .../modules/improvedigitalBidAdapter_spec.js | 24 ++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 1f19ebfa574..52067b2bf96 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -637,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; } diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js index 615feaa6619..7d6099e0de6 100644 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ b/test/spec/modules/improvedigitalBidAdapter_spec.js @@ -517,17 +517,19 @@ describe('Improve Digital Adapter Tests', function () { }); it('should set pagecat and genre ➞ fpd:ortb2.site', function() { - const bidRequest = Object.assign({}, simpleBidRequest); 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).is('array').equal(['IAB2-2']) - expect(params.bid_request.genre, 'Adventure'); + 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() { - const bidRequest = Object.assign({}, simpleBidRequest); 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; @@ -535,19 +537,25 @@ describe('Improve Digital Adapter Tests', function () { }); it('should use cat when pagecat not available ➞ fpd:ortb2.site', function() { - const bidRequest = Object.assign({}, simpleBidRequest); 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).is('array').equal(['IAB2']); + 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() { - const bidRequest = Object.assign({}, simpleBidRequest); 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).is('array').equal(['IAB2', 'IAB3']); + expect(params.bid_request.pagecat).to.be.an('array'); + expect(params.bid_request.pagecat).to.deep.equal([ + 'IAB2', + 'IAB3' + ] + ); }); });