Skip to content

Commit

Permalink
AdagioBidAdapter 2.1.0 - legacy branch (#4774)
Browse files Browse the repository at this point in the history
* adagioBidAdapter: avoid preflight requests

* adagioBidAdapter: always return computable features

AdagioBidAdapter: cast organizationId param as a string (#4721)

* AdagioBidAdapter: cast organizationId param as a string

* AdagioBidAdapter: Fix tests
  • Loading branch information
osazos authored and mkendall07 committed Jan 28, 2020
1 parent 106777d commit d013bb8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
43 changes: 24 additions & 19 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import JSEncrypt from 'jsencrypt/bin/jsencrypt';
import sha256 from 'crypto-js/sha256';

const BIDDER_CODE = 'adagio';
const VERSION = '2.0.0';
const VERSION = '2.1.0';
const FEATURES_VERSION = '1';
const ENDPOINT = 'https://mp.4dex.io/prebid';
const SUPPORTED_MEDIA_TYPES = ['banner'];
Expand Down Expand Up @@ -93,6 +93,9 @@ const _features = {
const viewportDims = _features.getViewPortDimensions().split('x');
const w = utils.getWindowTop();
const body = w.document.body;
if (!body) {
return ''
}
const html = w.document.documentElement;
const pageHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);

Expand Down Expand Up @@ -129,6 +132,8 @@ const _features = {
},

getSlotPosition: function(element) {
if (!element) return '';

const w = utils.getWindowTop();
const d = w.document;
const el = element;
Expand Down Expand Up @@ -288,22 +293,19 @@ function _getFeatures(bidRequest) {
element = w.document.getElementById(adUnitElementId);
}

let features = {};
if (element) {
features = Object.assign({}, {
print_number: _features.getPrintNumber(bidRequest.adUnitCode).toString(),
page_dimensions: _features.getPageDimensions().toString(),
viewport_dimensions: _features.getViewPortDimensions().toString(),
dom_loading: _features.isDomLoading().toString(),
// layout: features.getLayout().toString(),
adunit_position: _features.getSlotPosition(element).toString(),
user_timestamp: _features.getTimestamp().toString(),
device: _features.getDevice().toString(),
url: w.location.origin + w.location.pathname,
browser: _features.getBrowser(),
os: _features.getOS()
})
}
const features = {
print_number: _features.getPrintNumber(bidRequest.adUnitCode).toString(),
page_dimensions: _features.getPageDimensions().toString(),
viewport_dimensions: _features.getViewPortDimensions().toString(),
dom_loading: _features.isDomLoading().toString(),
// layout: features.getLayout().toString(),
adunit_position: _features.getSlotPosition(element).toString(),
user_timestamp: _features.getTimestamp().toString(),
device: _features.getDevice().toString(),
url: w.location.origin + w.location.pathname,
browser: _features.getBrowser(),
os: _features.getOS()
};

const adUnitFeature = {};
adUnitFeature[adUnitElementId] = {
Expand Down Expand Up @@ -351,7 +353,7 @@ export const spec = {
w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
isValid = !!(organizationId && site && placement && adUnitElementId && document.getElementById(adUnitElementId) !== null);
isValid = !!(organizationId && site && placement && adUnitElementId);
const tempAdUnits = w.ADAGIO.pbjsAdUnits.filter((adUnit) => adUnit.code !== adUnitCode);
tempAdUnits.push({
code: adUnitCode,
Expand Down Expand Up @@ -392,6 +394,9 @@ export const spec = {

// Regroug ad units by siteId
const groupedAdUnits = adUnits.reduce((groupedAdUnits, adUnit) => {
if (adUnit.params && adUnit.params.organizationId) {
adUnit.params.organizationId = adUnit.params.organizationId.toString();
}
(groupedAdUnits[adUnit.params.organizationId] = groupedAdUnits[adUnit.params.organizationId] || []).push(adUnit);
return groupedAdUnits;
}, {});
Expand All @@ -415,7 +420,7 @@ export const spec = {
featuresVersion: FEATURES_VERSION
},
options: {
contentType: 'application/json'
contentType: 'text/plain'
}
}
});
Expand Down
19 changes: 14 additions & 5 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('adagioAdapter', () => {
let utilsMock;
const adapter = newBidder(spec);
const ENDPOINT = 'https://mp.4dex.io/prebid';
const VERSION = '2.0.0';
const VERSION = '2.1.0';

beforeEach(function() {
localStorage.removeItem('adagioScript');
Expand Down Expand Up @@ -330,11 +330,11 @@ describe('adagioAdapter', () => {
expect(request.data.prebidVersion).to.equal('$prebid.version$');
});

it('features params must be empty if param adUnitElementId is not found', () => {
it('features params "adunit_position" must be empty if adUnitElement is not found in the DOM', () => {
const requests = spec.buildRequests([Object.assign({}, bidRequests[0], {params: {adUnitElementId: 'does-not-exist'}})], bidderRequest);
const request = requests[0];
const expected = {}
expect(request.data.adUnits[0].features).to.deep.equal(expected);
expect(request.data.adUnits[0].features).to.exist;
expect(request.data.adUnits[0].features.adunit_position).to.deep.equal('');
});

it('features params "adunit_position" should be computed even if DOM element is display:none', () => {
Expand Down Expand Up @@ -414,7 +414,16 @@ describe('adagioAdapter', () => {
const requests = spec.buildRequests([bidRequests[0]], bidderRequest);
const request = requests[0];
expect(request.data.adUnits[0].features.print_number).to.equal('2');
})
});

it('organizationId param key must be a string', () => {
const requests = spec.buildRequests([Object.assign({}, bidRequests[0], {params: {organizationId: 1010}})], bidderRequest);
const request = requests[0];
expect(request.data.adUnits[0].params).to.exist;
expect(request.data.adUnits[0].params.organizationId).to.deep.equal('1010');
expect(request.data.organizationId).to.exist;
expect(request.data.organizationId).to.deep.equal('1010');
});

it('GDPR consent is applied', () => {
const requests = spec.buildRequests(bidRequests, bidderRequest);
Expand Down

0 comments on commit d013bb8

Please sign in to comment.