Skip to content

Commit

Permalink
Adagio bid adapter 2.1.0 (#4704)
Browse files Browse the repository at this point in the history
* adagioBidAdapter: avoid preflight requests

* adagioBidAdapter: always return computable features
  • Loading branch information
osazos authored and jsnellbaker committed Jan 9, 2020
1 parent e365a48 commit 60a3317
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
40 changes: 21 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 @@ -415,7 +417,7 @@ export const spec = {
featuresVersion: FEATURES_VERSION
},
options: {
contentType: 'application/json'
contentType: 'text/plain'
}
}
});
Expand Down
8 changes: 4 additions & 4 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

0 comments on commit 60a3317

Please sign in to comment.