Skip to content

Commit

Permalink
EMX Digital: Device info and Video parameter updates (#3929)
Browse files Browse the repository at this point in the history
* EMX Digital - device info and video parameter updates

* update timeout value to grab from bidderRequest arg

* removing unused import

* removing object spread use. quote fix for lint

* remove space
  • Loading branch information
EMXDigital authored and jsnellbaker committed Jun 24, 2019
1 parent de8381f commit 37232c7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
85 changes: 57 additions & 28 deletions modules/emx_digitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';
import { config } from '../src/config';
import { Renderer } from '../src/Renderer';
import includes from 'core-js/library/fn/array/includes';

const BIDDER_CODE = 'emx_digital';
const ENDPOINT = 'hb.emxdgt.com';
const RENDERER_URL = '//js.brealtime.com/outstream/1.30.0/bundle.js';
const ADAPTER_VERSION = '1.40.2';
const DEFAULT_CUR = 'USD';

export const emxAdapter = {
validateSizes: (sizes) => {
Expand Down Expand Up @@ -48,6 +49,23 @@ export const emxAdapter = {
}
return bidResponse;
},
isMobile: () => {
return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent);
},
isConnectedTV: () => {
return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(navigator.userAgent);
},
getDevice: () => {
return {
ua: navigator.userAgent,
js: 1,
dnt: (navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1' || navigator.msDoNotTrack === '1') ? 1 : 0,
h: screen.height,
w: screen.width,
devicetype: emxAdapter.isMobile() ? 1 : emxAdapter.isConnectedTV() ? 3 : 2,
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage),
};
},
cleanProtocols: (video) => {
if (video.protocols && includes(video.protocols, 7)) {
// not supporting VAST protocol 7 (VAST 4.0);
Expand Down Expand Up @@ -85,10 +103,22 @@ export const emxAdapter = {
return renderer;
},
buildVideo: (bid) => {
bid.params.video = bid.params.video || {};
bid.params.video.h = bid.mediaTypes.video.playerSize[0][0];
bid.params.video.w = bid.mediaTypes.video.playerSize[0][1];
return emxAdapter.cleanProtocols(bid.params.video);
let videoObj = Object.assign(bid.mediaTypes.video, bid.params.video)
return emxAdapter.cleanProtocols(videoObj);
},
parseResponse: (bidResponseAdm) => {
try {
return decodeURIComponent(bidResponseAdm);
} catch (err) {
utils.logError('emx_digitalBidAdapter', 'error', err);
}
},
getReferrer: () => {
try {
return window.top.document.referrer;
} catch (err) {
return document.referrer;
}
},
getGdpr: (bidRequests, emxData) => {
if (bidRequests.gdprConsent) {
Expand Down Expand Up @@ -151,40 +181,44 @@ export const spec = {
return true;
},
buildRequests: function (validBidRequests, bidderRequest) {
const page = bidderRequest.refererInfo.referer;
let emxImps = [];
const timeout = config.getConfig('bidderTimeout');
const emxImps = [];
const timeout = bidderRequest.timeout || '';
const timestamp = Date.now();
const url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp);
const networkProtocol = location.protocol.indexOf('https') > -1 ? 1 : 0;
const url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp + '&src=pbjs');
const secure = location.protocol.indexOf('https') > -1 ? 1 : 0;
const domain = utils.getTopWindowLocation().hostname;
const page = bidderRequest.refererInfo.referer;
const device = emxAdapter.getDevice();
const ref = emxAdapter.getReferrer();

utils._each(validBidRequests, function (bid) {
let tagId = utils.getBidIdParameter('tagid', bid.params);
let bidFloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0;
let tagid = utils.getBidIdParameter('tagid', bid.params);
let bidfloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0;
let isVideo = !!bid.mediaTypes.video;
let data = {
id: bid.bidId,
tid: bid.transactionId,
tagid: tagId,
secure: networkProtocol
tagid,
secure
};
let typeSpecifics = isVideo ? { video: emxAdapter.buildVideo(bid) } : { banner: emxAdapter.buildBanner(bid) };
let emxBid = Object.assign(data, typeSpecifics);
let bidfloorObj = bidfloor > 0 ? { bidfloor, bidfloorcur: DEFAULT_CUR } : {};
let emxBid = Object.assign(data, typeSpecifics, bidfloorObj);

if (bidFloor > 0) {
emxBid.bidfloor = bidFloor
}
emxImps.push(emxBid);
});

let emxData = {
id: bidderRequest.auctionId,
imp: emxImps,
device,
site: {
domain: window.top.document.location.host,
page: page
domain,
page,
ref
},
version: '1.30.0'
cur: DEFAULT_CUR,
version: ADAPTER_VERSION
};

emxData = emxAdapter.getGdpr(bidderRequest, Object.assign({}, emxData));
Expand All @@ -204,6 +238,7 @@ export const spec = {
response.seatbid.forEach(function (emxBid) {
emxBid = emxBid.bid[0];
let isVideo = false;
let adm = emxAdapter.parseResponse(emxBid.adm) || '';
let bidResponse = {
requestId: emxBid.id,
cpm: emxBid.price,
Expand All @@ -214,7 +249,7 @@ export const spec = {
currency: 'USD',
netRevenue: true,
ttl: emxBid.ttl,
ad: decodeURIComponent(emxBid.adm)
ad: adm
};
if (emxBid.adm && emxBid.adm.indexOf('<?xml version=') > -1) {
isVideo = true;
Expand All @@ -234,12 +269,6 @@ export const spec = {
url: '//biddr.brealtime.com/check.html'
});
}
if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: '//edba.brealtime.com/'
});
}
return syncs;
}
};
Expand Down
7 changes: 2 additions & 5 deletions test/spec/modules/emx_digitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ describe('emx_digital Adapter', function () {
it('properly sends site information and protocol', function () {
request = spec.buildRequests(bidderRequest.bids, bidderRequest);
request = JSON.parse(request.data);
expect(request.site.domain).to.equal(window.top.document.location.host);
expect(request.site.domain).to.equal(utils.getTopWindowLocation().hostname);
expect(decodeURIComponent(request.site.page)).to.equal(bidderRequest.refererInfo.referer);
expect(request.site.ref).to.equal(window.top.document.referrer);
});

it('builds correctly formatted request banner object', function () {
Expand Down Expand Up @@ -511,10 +512,6 @@ describe('emx_digital Adapter', function () {
let iframeSync = spec.getUserSyncs(syncOptionsIframe);
expect(iframeSync.length).to.equal(1);
expect(iframeSync[0].type).to.equal('iframe');

let pixelSync = spec.getUserSyncs(syncOptionsPixel);
expect(pixelSync.length).to.equal(1);
expect(pixelSync[0].type).to.equal('image');
});
});
});

0 comments on commit 37232c7

Please sign in to comment.