Skip to content

Commit

Permalink
Axonix Bid Adapter: add new bid adapter (prebid#6341)
Browse files Browse the repository at this point in the history
* Add Axonix bid adapter

* Fixed tests
  • Loading branch information
cesarfd authored and seergiioo6 committed Mar 23, 2021
1 parent a8e1d37 commit f2ca498
Show file tree
Hide file tree
Showing 3 changed files with 690 additions and 0 deletions.
178 changes: 178 additions & 0 deletions modules/axonixBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import * as utils from '../src/utils.js';
import { ajax } from '../src/ajax.js';

const BIDDER_CODE = 'axonix';
const BIDDER_VERSION = '1.0.0';

const CURRENCY = 'USD';
const DEFAULT_REGION = 'us-east-1';

function getBidFloor(bidRequest) {
let floorInfo = {};

if (typeof bidRequest.getFloor === 'function') {
floorInfo = bidRequest.getFloor({
currency: CURRENCY,
mediaType: '*',
size: '*'
});
}

return floorInfo.floor || 0;
}

function getPageUrl(bidRequest, bidderRequest) {
let pageUrl = config.getConfig('pageUrl');

if (bidRequest.params.referrer) {
pageUrl = bidRequest.params.referrer;
} else if (!pageUrl) {
pageUrl = bidderRequest.refererInfo.referer;
}

return bidRequest.params.secure ? pageUrl.replace(/^http:/i, 'https:') : pageUrl;
}

function isMobile() {
return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent);
}

function isConnectedTV() {
return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(navigator.userAgent);
}

function getURL(params, path) {
let { supplyId, region, endpoint } = params;
let url;

if (endpoint) {
url = endpoint;
} else if (region) {
url = `https://openrtb-${region}.axonix.com/supply/${path}/${supplyId}`;
} else {
url = `https://openrtb-${DEFAULT_REGION}.axonix.com/supply/${path}/${supplyId}`
}

return url;
}

export const spec = {
code: BIDDER_CODE,
version: BIDDER_VERSION,
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function(bid) {
// video bid request validation
if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) {
if (!bid.mediaTypes[VIDEO].hasOwnProperty('mimes') ||
!utils.isArray(bid.mediaTypes[VIDEO].mimes) ||
bid.mediaTypes[VIDEO].mimes.length === 0) {
utils.logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid));

return false;
}
}

return !!(bid.params && bid.params.supplyId);
},

buildRequests: function(validBidRequests, bidderRequest) {
// device.connectiontype
let connection = navigator.connection || navigator.webkitConnection;
let connectiontype = 'unknown';

if (connection && connection.effectiveType) {
connectiontype = connection.effectiveType;
}

const requests = validBidRequests.map(validBidRequest => {
// app/site
let app;
let site;

if (typeof config.getConfig('app') === 'object') {
app = config.getConfig('app');
} else {
site = {
page: getPageUrl(validBidRequest, bidderRequest)
}
}

const data = {
app,
site,
validBidRequest,
connectiontype,
devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2,
bidfloor: getBidFloor(validBidRequest),
dnt: (navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1' || navigator.msDoNotTrack === '1') ? 1 : 0,
language: navigator.language,
prebidVersion: '$prebid.version$',
screenHeight: screen.height,
screenWidth: screen.width,
tmax: config.getConfig('bidderTimeout'),
ua: navigator.userAgent,
};

return {
method: 'POST',
url: getURL(validBidRequest.params, 'prebid'),
options: {
withCredentials: false,
contentType: 'application/json'
},
data
};
});

return requests;
},

interpretResponse: function(serverResponse) {
if (!utils.isArray(serverResponse)) {
return [];
}

const responses = [];

for (const response of serverResponse) {
if (response.requestId) {
responses.push(Object.assign(response, {
ttl: config.getConfig('_bidderTimeout')
}));
}
}

return responses;
},

onTimeout: function(timeoutData) {
const params = utils.deepAccess(timeoutData, '0.params.0');

if (!utils.isEmpty(params)) {
ajax(getURL(params, 'prebid/timeout'), null, timeoutData[0], {
method: 'POST',
options: {
withCredentials: false,
contentType: 'application/json'
}
});
}
},

onBidWon: function(bids) {
for (const bid of bids) {
const { nurl } = bid || {};

if (bid.nurl) {
utils.replaceAuctionPrice(nurl, bid.cpm)
utils.triggerPixel(nurl);
};
}
}
}

registerBidder(spec);
140 changes: 140 additions & 0 deletions modules/axonixBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Overview

```
Module Name : Axonix Bidder Adapter
Module Type : Bidder Adapter
Maintainer : [email protected]
```

# Description

Module that connects to Axonix's exchange for bids.

# Parameters

| Name | Scope | Description | Example |
| :------------ | :------- | :---------------------------------------------- | :------------------------------------- |
| `supplyId` | required | Supply UUID | `"2c426f78-bb18-4a16-abf4-62c6cd0ee8de"` |
| `region` | optional | Cloud region | `"us-east-1"` |
| `endpoint` | optional | Supply custom endpoint | `"https://open-rtb.axonix.com/custom"` |
| `instl` | optional | Set to 1 if using interstitial (default: 0) | `1` |

# Test Parameters

## Banner

```javascript
var bannerAdUnit = {
code: 'test-banner',
mediaTypes: {
banner: {
sizes: [[120, 600], [300, 250], [320, 50], [468, 60], [728, 90]]
}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
};
```

## Video

```javascript
var videoAdUnit = {
code: 'test-video',
mediaTypes: {
video: {
protocols: [1, 2, 3, 4, 5, 6, 7, 8]
}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
};
```

## Native

```javascript
var nativeAdUnit = {
code: 'test-native',
mediaTypes: {
native: {

}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
};
```

## Multiformat

```javascript
var adUnits = [
{
code: 'test-banner',
mediaTypes: {
banner: {
sizes: [[120, 600], [300, 250], [320, 50], [468, 60], [728, 90]]
}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
},
{
code: 'test-video',
mediaTypes: {
video: {
protocols: [1, 2, 3, 4, 5, 6, 7, 8]
}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
},
{
code: 'test-native',
mediaTypes: {
native: {

}
},
bids: [{
bidder: 'axonix',
params: {
supplyId: 'abc',
region: 'def',
endpoint: 'url'
}
}]
}
];
```
Loading

0 comments on commit f2ca498

Please sign in to comment.