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

Optimera Adapter for 1.0 (#1759) #1760

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
81 changes: 81 additions & 0 deletions modules/optimeraBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {registerBidder} from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'optimera';
const SCORES_BASE_URL = 'https://s3.amazonaws.com/elasticbeanstalk-us-east-1-397719490216/json/client/';

export const spec = {
code: BIDDER_CODE,
/**
* Determines whether or not the given bid request is valid.
*
* @param {bidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bidRequest) {
if (typeof bidRequest.params.custom != 'undefined' && typeof bidRequest.params.custom.clientID != 'undefined') {
return true;
} else {
return false;
}
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests) {
var optimeraHost = window.location.host;
var optimeraPathName = window.location.pathname;
var timestamp = Math.round(new Date().getTime() / 1000);
if (typeof validBidRequests[0].params.custom.clientID != 'undefined') {
var clientID = validBidRequests[0].params.custom.clientID;
var scoresURL = SCORES_BASE_URL + clientID + '/' + optimeraHost + optimeraPathName + '.js';
return {
method: 'GET',
url: scoresURL,
payload: validBidRequests,
data: {'t': timestamp}
};
}
},
/**
* Unpack the response from the server into a list of bids.
*
* Some required bid params are not needed for this so default
* values are used.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
var scores = serverResponse.body.replace('window.oVa = ', '');
scores = scores.replace(';', '');
scores = JSON.parse(scores);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any JSON.parse calls will need to be in a try/catch block

var validBids = bidRequest.payload;
var bidResponses = [];
var dealId = '';
for (var i = 0; i < validBids.length; i++) {
if (typeof validBids[i].params.custom.clientID != 'undefined') {
if (validBids[i].adUnitCode in scores) {
dealId = scores[validBids[i].adUnitCode];
}
var bidResponse = {
requestId: validBids[i].bidId,
ad: '<div></div>',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might have been mentioned before, but how do you render the ad if there is no ad content?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @mkendall07, we are just creating this adpator to add visibility scores for the ad divs that will be added to DFP calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok but what does a publisher do with that information? And why is a request to your endpoint required to calculate viewability?

cpm: 0.01,
width: 0,
height: 0,
dealId: dealId,
ttl: 300,
creativeId: '1',
netRevenue: '0',
currency: 'USD'
};
bidResponses.push(bidResponse);
}
}
return bidResponses;
}
}

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

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

# Description

Module that adds ad placement visibility scores for DFP.

# Test Parameters
```
var adUnits = [{
code: 'div-1',
sizes: [[300, 250], [300,600]],
bids: [
{
bidder: 'optimera',
params: {
custom:{
clientID: '0'
}
}
}]
},{
code: 'div-0',
sizes: [[728, 90]],
bids: [
{
bidder: 'optimera',
params: {
custom:{
clientID: '0'
}
}
}]
}];
```
83 changes: 83 additions & 0 deletions test/spec/modules/optimeraBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { expect } from 'chai';
import { spec } from 'modules/optimeraBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';

describe('OptimeraAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
})

describe('isBidRequestValid', () => {
let bid = {
'bidder': 'optimera',
'params': {
'custom': {
'clientID': '0'
}
},
'adUnitCode': 'div-0',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});
})

describe('buildRequests', () => {
let bid = [
{
'adUnitCode': 'div-0',
'auctionId': '1ab30503e03994',
'bidId': '313e0afede8cdb',
'bidder': 'optimera',
'bidderRequestId': '202be1ce3f6194',
'params': {
'custom': {
'clientID': '0'
}
}
}
];
it('buildRequests fires', () => {
let request = spec.buildRequests(bid);
expect(request).to.exist;
expect(request.method).to.equal('GET');
expect(request.payload).to.exist;
expect(request.data.t).to.exist;
});
})

describe('interpretResponse', () => {
let serverResponse = {};
serverResponse.body = 'window.oVa = {"div-0":["RB_K","728x90K"], "timestamp":["RB_K","1507565666"]};';
var bidRequest = {
'method': 'get',
'payload': [
{
'bidder': 'optimera',
'params': {
'custom': {
'clientID': '0'
}
},
'adUnitCode': 'div-0',
'bidId': '307440db8538ab'
}
]
}
it('interpresResponse fires', () => {
window.oDv = window.oDv || [];
let bidResponses = spec.interpretResponse(serverResponse, bidRequest);
expect(bidResponses[0].dealId[0]).to.equal('RB_K');
expect(bidResponses[0].dealId[1]).to.equal('728x90K');
});
});
});