Skip to content

Commit

Permalink
Media.net Adapter: Support Prebid 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy-chitale committed Oct 24, 2019
1 parent 6114a3d commit 5c6048f
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 30 deletions.
36 changes: 28 additions & 8 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import * as utils from '../src/utils';
import { config } from '../src/config';
import * as url from '../src/url';
import { BANNER, NATIVE } from '../src/mediaTypes';
import { getRefererInfo } from '../src/refererDetection';

const BIDDER_CODE = 'medianet';
const BID_URL = '//prebid.media.net/rtb/prebid';
const BID_URL = 'https://prebid.media.net/rtb/prebid';
const SLOT_VISIBILITY = {
NOT_DETERMINED: 0,
ABOVE_THE_FOLD: 1,
Expand All @@ -17,16 +18,32 @@ const EVENTS = {
};
const EVENT_PIXEL_URL = 'qsearch-a.akamaihd.net/log';

let refererInfo = getRefererInfo();

let mnData = {};
mnData.urlData = {
domain: url.parse(refererInfo.referer).host,
page: refererInfo.referer,
isTop: refererInfo.reachedTop
}

$$PREBID_GLOBAL$$.medianetGlobals = {};

function getTopWindowReferrer() {
try {
return window.top.document.referrer;
} catch (e) {
return document.referrer;
}
}

function siteDetails(site) {
site = site || {};
let siteData = {
domain: site.domain || utils.getTopWindowLocation().host,
page: site.page || utils.getTopWindowUrl(),
ref: site.ref || utils.getTopWindowReferrer()
domain: site.domain || mnData.urlData.domain,
page: site.page || mnData.urlData.page,
ref: site.ref || getTopWindowReferrer(),
isTop: site.isTop || mnData.urlData.isTop
};

return Object.assign(siteData, getPageMeta());
Expand Down Expand Up @@ -141,8 +158,10 @@ function slotParams(bidRequest) {
},
all: bidRequest.params
};
if (bidRequest.sizes.length > 0) {
params.banner = transformSizes(bidRequest.sizes);
let bannerSizes = utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes || [];

if (bannerSizes.length > 0) {
params.banner = transformSizes(bannerSizes);
}
if (bidRequest.nativeParams) {
try {
Expand Down Expand Up @@ -252,8 +271,9 @@ function getLoggingData(event, data) {
params.cid = $$PREBID_GLOBAL$$.medianetGlobals.cid || '';
params.crid = data.map((adunit) => utils.deepAccess(adunit, 'params.0.crid') || adunit.adUnitCode).join('|');
params.adunit_count = data.length || 0;
params.dn = utils.getTopWindowLocation().host || '';
params.requrl = utils.getTopWindowUrl() || '';
params.dn = mnData.urlData.domain || '';
params.requrl = mnData.urlData.page || '';
params.istop = mnData.urlData.isTop || '';
params.event = event.name || '';
params.value = event.value || '';
params.rd = event.related_data || '';
Expand Down
109 changes: 87 additions & 22 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]],
}
},
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand All @@ -26,7 +31,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
Expand All @@ -45,12 +51,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]],
}
},
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand All @@ -62,12 +74,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
'sizes': [[300, 251]],
'mediaTypes': {
'banner': {
'sizes': [[300, 251]],
}
},
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand All @@ -80,12 +98,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'sizes': [[300, 250]],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]],
}
},
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand Down Expand Up @@ -127,12 +151,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
'sizes': [[300, 251]],
'mediaTypes': {
'banner': {
'sizes': [[300, 251]],
}
},
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand Down Expand Up @@ -170,12 +200,18 @@ let VALID_BID_REQUEST = [{
}],
VALID_AUCTIONDATA = {
'timeout': config.getConfig('bidderTimeout'),
'refererInfo': {
referer: 'http://media.net/prebidtest',
stack: ['http://media.net/prebidtest'],
reachedTop: true
}
},
VALID_PAYLOAD_INVALID_BIDFLOOR = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
},
'ext': {
'customer_id': 'customer_id',
Expand Down Expand Up @@ -215,7 +251,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}, {
Expand Down Expand Up @@ -245,7 +282,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}],
Expand All @@ -255,7 +293,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
},
'ext': {
'customer_id': 'customer_id',
Expand Down Expand Up @@ -295,7 +334,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}, {
Expand Down Expand Up @@ -326,7 +366,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}],
Expand All @@ -336,7 +377,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
},
'ext': {
'customer_id': 'customer_id',
Expand Down Expand Up @@ -375,7 +417,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}, {
Expand Down Expand Up @@ -405,7 +448,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}],
Expand Down Expand Up @@ -548,12 +592,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'sizes': [300, 250],
'mediaTypes': {
'banner': {
'sizes': [[300, 250]],
}
},
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand All @@ -565,12 +615,18 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
'sizes': [300, 251],
'mediaTypes': {
'banner': {
'sizes': [[300, 251]],
}
},
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
Expand All @@ -581,13 +637,20 @@ let VALID_BID_REQUEST = [{
'consentString': 'consentString',
'gdprApplies': true,
},
'timeout': 3000
'timeout': 3000,
refererInfo: {
referer: 'http://media.net/prebidtest',
stack: ['http://media.net/prebidtest'],
reachedTop: true
}
},
VALID_PAYLOAD_FOR_GDPR = {
'site': {
'domain': 'media.net',
'page': 'http://media.net/prebidtest',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true

},
'ext': {
'customer_id': 'customer_id',
Expand Down Expand Up @@ -627,7 +690,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}, {
Expand Down Expand Up @@ -657,7 +721,8 @@ let VALID_BID_REQUEST = [{
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}],
Expand Down

0 comments on commit 5c6048f

Please sign in to comment.