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

Update Atomx adapter for Prebid v1.0 #2026

Merged
merged 2 commits into from
Jan 22, 2018
Merged
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
107 changes: 107 additions & 0 deletions modules/atomxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'atomx';

function getDomain() {
var domain = '';

try {
if ((domain === '') && (window.top == window)) {
domain = window.location.href;
}

if ((domain === '') && (window.top == window.parent)) {
domain = document.referrer;
}

if (domain == '') {
var atomxt = 'atomxtest';

// It should be impossible to change the window.location.ancestorOrigins.
window.location.ancestorOrigins[0] = atomxt;
if (window.location.ancestorOrigins[0] != atomxt) {
var ancestorOrigins = window.location.ancestorOrigins;

// If the length is 0 we are a javascript tag running in the main domain.
// But window.top != window or window.location.hostname is empty.
if (ancestorOrigins.length == 0) {
// This browser is so fucked up, just return an empty string.
return '';
}

// ancestorOrigins is an array where [0] is our own window.location
// and [length-1] is the top window.location.
domain = ancestorOrigins[ancestorOrigins.length - 1];
}
}
} catch (unused) {
}

if (domain === '') {
domain = document.referrer;
}

if (domain === '') {
domain = window.location.href;
}

return domain.substr(0, 512);
}

export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function(bid) {
return bid.params && (!!bid.params.id);
},

buildRequests: function(validBidRequests) {
return validBidRequests.map(bidRequest => {
return {
method: 'GET',
url: location.protocol + '//p.ato.mx/placement',
data: {
v: 12,
id: bidRequest.params.id,
size: utils.parseSizesInput(bidRequest.sizes)[0],
prebid: bidRequest.bidId,
b: 0,
h: '7t3y9',
type: 'javascript',
screen: window.screen.width + 'x' + window.screen.height + 'x' + window.screen.colorDepth,
timezone: new Date().getTimezoneOffset(),
domain: getDomain(),
r: document.referrer.substr(0, 512),
},
};
});
},

interpretResponse: function (serverResponse, bidRequest) {
const body = serverResponse.body;
const res = {
requestId: body.code,
cpm: body.cpm * 1000,
width: body.width,
height: body.height,
creativeId: body.creative_id,
currency: 'USD',
netRevenue: true,
ttl: 60,
};

if (body.adm) {
res.ad = body.adm;
} else {
res.adUrl = body.url;
}

return [res];
},

getUserSyncs: function(syncOptions, serverResponses) {
return [];
},
};
registerBidder(spec);
25 changes: 25 additions & 0 deletions modules/atomxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Overview
Module Name: Atomx Bidder Adapter Module
Type: Bidder Adapter
Maintainer: [email protected]

# Description
Atomx Bidder Adapter for Prebid.js.

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]],
bids: [
{
bidder: 'atomx',
params: {
id: 4025860,
}
}
]
}
];
```
119 changes: 119 additions & 0 deletions test/spec/modules/atomxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { expect } from 'chai';
import { spec } from 'modules/atomxBidAdapter';

describe('atomxAdapterTest', () => {
describe('bidRequestValidity', () => {
it('bidRequest with id param', () => {
expect(spec.isBidRequestValid({
bidder: 'atomx',
params: {
id: 1234,
},
})).to.equal(true);
});

it('bidRequest with no id param', () => {
expect(spec.isBidRequestValid({
bidder: 'atomx',
params: {
},
})).to.equal(false);
});
});

describe('bidRequest', () => {
const bidRequests = [{
'bidder': 'atomx',
'params': {
'id': '123'
},
'adUnitCode': 'aaa',
'transactionId': '1b8389fe-615c-482d-9f1a-177fb8f7d5b0',
'sizes': [300, 250],
'bidId': '1abgs362e0x48a8',
'bidderRequestId': '70deaff71c281d',
'auctionId': '5c66da22-426a-4bac-b153-77360bef5337'
},
{
'bidder': 'atomx',
'params': {
'id': '456',
},
'adUnitCode': 'bbb',
'transactionId': '193995b4-7122-4739-959b-2463282a138b',
'sizes': [[800, 600]],
'bidId': '22aidtbx5eabd9',
'bidderRequestId': '70deaff71c281d',
'auctionId': 'e97cafd0-ebfc-4f5c-b7c9-baa0fd335a4a'
}];

it('bidRequest HTTP method', () => {
const requests = spec.buildRequests(bidRequests);
requests.forEach(function(requestItem) {
expect(requestItem.method).to.equal('GET');
});
});

it('bidRequest url', () => {
const requests = spec.buildRequests(bidRequests);
requests.forEach(function(requestItem) {
expect(requestItem.url).to.match(new RegExp('p\\.ato\\.mx/placement'));
});
});

it('bidRequest data', () => {
const requests = spec.buildRequests(bidRequests);
expect(requests[0].data.id).to.equal('123');
expect(requests[0].data.size).to.equal('300x250');
expect(requests[0].data.prebid).to.equal('1abgs362e0x48a8');
expect(requests[1].data.id).to.equal('456');
expect(requests[1].data.size).to.equal('800x600');
expect(requests[1].data.prebid).to.equal('22aidtbx5eabd9');
});
});

describe('interpretResponse', () => {
const bidRequest = {
'method': 'GET',
'url': 'https://p.ato.mx/placement',
'data': {
'v': 12,
'id': '123',
'size': '300x250',
'prebid': '22aidtbx5eabd9',
'b': 0,
'h': '7t3y9',
'type': 'javascript',
'screen': '800x600x32',
'timezone': 0,
'domain': 'https://example.com',
'r': '',
}
};

const bidResponse = {
body: {
'cpm': 0.00009,
'width': 300,
'height': 250,
'url': 'http://atomx.com',
'creative_id': 456,
'code': '22aidtbx5eabd9',
},
headers: {}
};

it('result is correct', () => {
const result = spec.interpretResponse(bidResponse, bidRequest);

expect(result[0].requestId).to.equal('22aidtbx5eabd9');
expect(result[0].cpm).to.equal(0.00009 * 1000);
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(250);
expect(result[0].creativeId).to.equal(456);
expect(result[0].currency).to.equal('USD');
expect(result[0].ttl).to.equal(60);
expect(result[0].adUrl).to.equal('http://atomx.com');
});
});
});