Skip to content

Commit

Permalink
Media.net : Native support added
Browse files Browse the repository at this point in the history
  • Loading branch information
vedant.s committed Jan 11, 2019
1 parent c07e60d commit ab82a39
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 4 deletions.
16 changes: 14 additions & 2 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import { config } from 'src/config';
import * as url from 'src/url';
import { BANNER, NATIVE } from 'src/mediaTypes';

const BIDDER_CODE = 'medianet';
const BID_URL = '//prebid.media.net/rtb/prebid';
Expand Down Expand Up @@ -138,9 +139,18 @@ function slotParams(bidRequest) {
dfp_id: bidRequest.adUnitCode,
display_count: bidRequest.bidRequestsCount
},
banner: transformSizes(bidRequest.sizes),
all: bidRequest.params
};
if (bidRequest.sizes.length > 0) {
params.banner = transformSizes(bidRequest.sizes);
}
if (bidRequest.nativeParams) {
try {
params.native = JSON.stringify(bidRequest.nativeParams);
} catch (e) {
utils.logError((`${BIDDER_CODE} : Incorrect JSON : bidRequest.nativeParams`));
}
}

if (bidRequest.params.crid) {
params.tagid = bidRequest.params.crid.toString();
Expand All @@ -151,7 +161,7 @@ function slotParams(bidRequest) {
params.bidfloor = bidFloor;
}
const coordinates = getCoordinates(bidRequest.adUnitCode);
if (coordinates) {
if (coordinates && params.banner && params.banner.length !== 0) {
let normCoordinates = normalizeCoordinates(coordinates);
params.ext.coordinates = normCoordinates;
params.ext.viewability = getSlotVisibility(coordinates.top_left, getMinSize(params.banner));
Expand Down Expand Up @@ -268,6 +278,8 @@ export const spec = {

code: BIDDER_CODE,

supportedMediaTypes: [BANNER, NATIVE],

/**
* Determines whether or not the given bid request is valid.
*
Expand Down
46 changes: 44 additions & 2 deletions modules/medianetBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var adUnits = [{
}];
```

# Ad Unit and Setup: For Testing
# Ad Unit and Setup: For Testing (Banner)

```html
<!-- Prebid Config section -->
Expand All @@ -56,4 +56,46 @@ var adUnits = [{
pbjs.que = pbjs.que || [];
</script>
<!-- End Prebid Config section -->
```
```


# Ad Unit and Setup: For Testing (Native)

```html
<!-- Prebid Config section -->
<script>
var PREBID_TIMEOUT = 2000;
var adUnits = [
{
code: 'div-gpt-ad-1544091247692-0',
mediaTypes: {
native: {
image: {
required: true,
sizes: [300, 250],
wmin: 50,
},
title: {
required: true,
len: 80
}
}
},
bids: [
{
bidder: 'medianet',
params: {
cid: '8CUX0H51C',
// Site member is to be used only for testing
site: {
page: 'http://smoketesting.net/prebidtest/',
domain: 'smoketesting.net',
ref: 'http://smoketesting.net/prebidtest/'
}
}
}
]
}
];
</script>
<!-- End Prebid Config section -->
181 changes: 181 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,101 @@ let VALID_BID_REQUEST = [{
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1
}],
VALID_NATIVE_BID_REQUEST = [{
'bidder': 'medianet',
'params': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'sizes': [[300, 250]],
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1,
'nativeParams': {
'image': {
'required': true,
'sizes': [
150,
50
],
'wmin': 50
},
'title': {
'required': true,
'len': 80
},
'sponsoredBy': {
'required': true
},
'clickUrl': {
'required': true
},
'body': {
'required': true
},
'icon': {
'required': true,
'sizes': [
50,
50
]
}
}
}, {
'bidder': 'medianet',
'params': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
'sizes': [[300, 251]],
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1,
'nativeParams': {
'image': {
'required': true,
'sizes': [
150,
50
],
'wmin': 50
},
'title': {
'required': true,
'len': 80
},
'sponsoredBy': {
'required': true
},
'clickUrl': {
'required': true
},
'body': {
'required': true
},
'icon': {
'required': true,
'sizes': [
50,
50
]
}
}
}],
VALID_AUCTIONDATA = {
'timeout': config.getConfig('bidderTimeout'),
},
Expand Down Expand Up @@ -156,6 +251,87 @@ let VALID_BID_REQUEST = [{
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD_NATIVE = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
},
'ext': {
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version,
'gdpr_applies': false,
'screen': {
'w': 1000,
'h': 1000
}
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
'id': '28f8f8130a583e',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-0',
'visibility': 1,
'viewability': 1,
'coordinates': {
'top_left': {
x: 50,
y: 50
},
'bottom_right': {
x: 100,
y: 100
}
},
'display_count': 1
},
'banner': [{
'w': 300,
'h': 250
}],
'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}',
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}, {
'id': '3f97ca71b1e5c2',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-123',
'visibility': 1,
'viewability': 1,
'coordinates': {
'top_left': {
x: 50,
y: 50
},
'bottom_right': {
x: 100,
y: 100
}
},
'display_count': 1
},
'banner': [{
'w': 300,
'h': 251
}],
'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}',
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD = {
'site': {
'page': 'http://media.net/prebidtest',
Expand Down Expand Up @@ -562,6 +738,11 @@ describe('Media.net bid adapter', function () {
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_FOR_GDPR);
});

it('should parse params for native request', function () {
let bidReq = spec.buildRequests(VALID_NATIVE_BID_REQUEST, VALID_AUCTIONDATA);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_NATIVE);
});

describe('build requests: when page meta-data is available', () => {
beforeEach(() => {
spec.clearMnData();
Expand Down

0 comments on commit ab82a39

Please sign in to comment.