Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addressed feedback from #3731 ticket #3752

Merged
merged 5 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 132 additions & 67 deletions modules/emx_digitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,96 +1,155 @@
import * as utils from '../src/utils';
import {
registerBidder
} from '../src/adapters/bidderFactory';
import {
BANNER
} from '../src/mediaTypes';
import {
config
} from '../src/config';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';
import { config } from '../src/config';
import includes from 'core-js/library/fn/array/includes';

const BIDDER_CODE = 'emx_digital';
const ENDPOINT = 'hb.emxdgt.com';

let emxAdapter = {};
export const emxAdapter = {
validateSizes: (sizes) => {
if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') {
utils.logWarn(BIDDER_CODE + ': Sizes should be an array');
return false;
}
return sizes.every(size => utils.isArray(size) && size.length === 2);
},
checkVideoContext: (bid) => {
return (bid && bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.context && bid.mediaTypes.video.context === 'instream');
},
buildBanner: (bid) => {
let sizes = [];
bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes ? sizes = bid.mediaTypes.banner.sizes : sizes = bid.sizes;
if (!emxAdapter.validateSizes(sizes)) {
utils.logWarn(BIDDER_CODE + ': could not detect mediaType banner sizes. Assigning to bid sizes instead');
sizes = bid.sizes
}
return {
format: sizes.map((size) => {
return {
w: size[0],
h: size[1]
};
}),
w: sizes[0][0],
h: sizes[0][1]
};
},
formatVideoResponse: (bidResponse, emxBid) => {
bidResponse.vastXml = emxBid.adm;
return bidResponse;
},
buildVideo: (bid) => {
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);
},
cleanProtocols: (video) => {
if (video.protocols && includes(video.protocols, 7)) {
utils.logWarn(BIDDER_CODE + ': VAST 4.0 is currently not supported. This protocol has been filtered out of the request.');
video.protocols = video.protocols.filter(protocol => protocol !== 7);
}
return video;
},
getGdpr: (bidRequests, emxData) => {
if (bidRequests.gdprConsent) {
emxData.regs = {
ext: {
gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0
}
};
}
if (bidRequests.gdprConsent && bidRequests.gdprConsent.gdprApplies) {
emxData.user = {
ext: {
consent: bidRequests.gdprConsent.consentString
}
};
}

emxAdapter.validateSizes = function(sizes) {
if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') {
return false;
return emxData;
}
return sizes.every(size => utils.isArray(size) && size.length === 2);
}
};

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function (bid) {
return !!bid.params.tagid &&
typeof bid.params.tagid === 'string' &&
(typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'string') &&
bid.bidder === BIDDER_CODE &&
(emxAdapter.validateSizes(bid.mediaTypes.banner.sizes) || emxAdapter.validateSizes(bid.sizes));
if (!bid || !bid.params) {
utils.logWarn(BIDDER_CODE + ': Missing bid or bid params.');
return false;
}

if (bid.bidder !== BIDDER_CODE) {
utils.logWarn(BIDDER_CODE + ': Must use "emx_digital" as bidder code.');
return false;
}

if (!bid.params.tagid || !utils.isStr(bid.params.tagid)) {
utils.logWarn(BIDDER_CODE + ': Missing tagid param or tagid present and not type String.');
return false;
}

if (bid.mediaTypes && bid.mediaTypes.banner) {
let sizes;
bid.mediaTypes.banner.sizes ? sizes = bid.mediaTypes.banner.sizes : sizes = bid.sizes;
if (!emxAdapter.validateSizes(sizes)) {
utils.logWarn(BIDDER_CODE + ': Missing sizes in bid');
return false;
}
} else if (bid.mediaTypes && bid.mediaTypes.video) {
if (!emxAdapter.checkVideoContext(bid)) {
utils.logWarn(BIDDER_CODE + ': Missing video context: instream');
return false;
}

if (!bid.mediaTypes.video.playerSize) {
utils.logWarn(BIDDER_CODE + ': Missing video playerSize');
return false;
}
}

return true;
},
buildRequests: function (validBidRequests, bidRequests) {
const {host, href, protocol} = utils.getTopWindowLocation();
let emxData = {};
buildRequests: function (validBidRequests, bidderRequest) {
const page = bidderRequest.refererInfo.referer;
let emxImps = [];
const auctionId = bidRequests.auctionId;
const timeout = config.getConfig('bidderTimeout');
const timestamp = Date.now();
const url = location.protocol + '//' + ENDPOINT + ('?t=' + timeout + '&ts=' + timestamp);
const networkProtocol = protocol.indexOf('https') > -1 ? 1 : 0;
const networkProtocol = location.protocol.indexOf('https') > -1 ? 1 : 0;

utils._each(validBidRequests, function (bid) {
let tagId = utils.getBidIdParameter('tagid', bid.params);
let bidFloor = parseFloat(utils.getBidIdParameter('bidfloor', bid.params)) || 0;
let sizes = bid.mediaTypes.banner.sizes;
if (!emxAdapter.validateSizes(sizes)) {
sizes = bid.sizes
}
let emxBid = {
let isVideo = !!bid.mediaTypes.video;
let data = {
id: bid.bidId,
tid: bid.transactionId,
tagid: tagId,
secure: networkProtocol,
banner: {
format: sizes.map(function (size) {
return {
w: size[0],
h: size[1]
};
}),
w: sizes[0][0],
h: sizes[0][1]
}
}
secure: networkProtocol
};
let typeSpecifics = isVideo ? { video: emxAdapter.buildVideo(bid) } : { banner: emxAdapter.buildBanner(bid) };
let emxBid = Object.assign(data, typeSpecifics);

if (bidFloor > 0) {
emxBid.bidfloor = bidFloor
}
emxImps.push(emxBid);
});
emxData = {
id: auctionId,

let emxData = {
id: bidderRequest.auctionId,
imp: emxImps,
site: {
domain: host,
page: href
}
domain: window.top.document.location.host,
page: page
},
version: '1.21.1'
};
if (bidRequests.gdprConsent) {
emxData.regs = {
ext: {
gdpr: bidRequests.gdprConsent.gdprApplies === true ? 1 : 0
}
};
}
if (bidRequests.gdprConsent && bidRequests.gdprConsent.gdprApplies) {
emxData.user = {
ext: {
consent: bidRequests.gdprConsent.consentString
}
};
}

emxData = emxAdapter.getGdpr(bidderRequest, Object.assign({}, emxData));
return {
method: 'POST',
url: url,
Expand All @@ -106,7 +165,8 @@ export const spec = {
if (response.seatbid && response.seatbid.length > 0 && response.seatbid[0].bid) {
response.seatbid.forEach(function (emxBid) {
emxBid = emxBid.bid[0];
emxBidResponses.push({
let isVideo = false;
let bidResponse = {
requestId: emxBid.id,
cpm: emxBid.price,
width: emxBid.w,
Expand All @@ -115,10 +175,15 @@ export const spec = {
dealId: emxBid.dealid || null,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: decodeURIComponent(emxBid.adm),
ttl: emxBid.ttl
});
ttl: emxBid.ttl,
ad: decodeURIComponent(emxBid.adm)
};
if (emxBid.adm && emxBid.adm.indexOf('<?xml version=') > -1) {
isVideo = true;
bidResponse = emxAdapter.formatVideoResponse(bidResponse, Object.assign({}, emxBid));
}
bidResponse.mediaType = (isVideo ? VIDEO : BANNER);
emxBidResponses.push(bidResponse);
});
}
return emxBidResponses;
Expand Down
28 changes: 26 additions & 2 deletions modules/emx_digitalBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Maintainer: git@emxdigital.com

# Description

The EMX Digital adapter provides publishers with access to the EMX Marketplace. The adapter is GDPR compliant. Please note that the adapter supports Banner media type only.
The EMX Digital adapter provides publishers with access to the EMX Marketplace. The adapter is GDPR compliant. Please note that the adapter supports Banner and Video (Instream) media types only.

Note: The EMX Digital adapter requires approval and implementation guidelines from the EMX team, including existing publishers that work with EMX Digital. Please reach out to your account manager or prebid@emxdigital.com for more information.

Expand All @@ -23,7 +23,7 @@ var adUnits = [{
code: 'banner-div',
mediaTypes: {
banner: {
sizes: [
sizes: [
[300, 250], [300, 600]
}
},
Expand All @@ -36,3 +36,27 @@ var adUnits = [{
}]
}];
```

# Video Example
```
var adUnits = [{
code: 'video-div',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480]
}
},
bids: [
{
bidder: 'emx_digital',
params: {
tagid: '25251',
video: {
skippable: true,
playback_methods: ['auto_play_sound_off']
}
}
}]
}];
```
Loading