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

New adapter "Cointraffic" added #5695

Merged
merged 3 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
New adapter "Cointraffic" added
  • Loading branch information
stsepelin committed Sep 3, 2020
commit 0a489f4c6972e5d3ba60809be9cd9cc720ff994e
104 changes: 104 additions & 0 deletions modules/cointrafficBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'cointraffic';
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';

function detectDevice() {
let hasTouchScreen
if ('maxTouchPoints' in navigator) {
hasTouchScreen = navigator.maxTouchPoints > 0
} else {
let mQ = window.matchMedia && matchMedia('(pointer:coarse)')
if (mQ && mQ.media === '(pointer:coarse)') {
hasTouchScreen = !!mQ.matches
} else if ('orientation' in window) {
hasTouchScreen = true // deprecated, but good fallback
} else {
// Only as a last resort, fall back to user agent sniffing
let UA = navigator.userAgent
hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA)
}
}

return hasTouchScreen && window.innerWidth < 1280 ? 'mobile' : 'desktop'
}

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 (bid) {
return !!(bid.params.placementId);
},

/**
* Make a server request from the list of BidRequests.
*
* @param validBidRequests
* @param bidderRequest
* @return Array Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return [];
}

const device = detectDevice()

return validBidRequests.map(bidRequest => {
const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes);

const payload = {
placementId: bidRequest.params.placementId,
device: device,
sizes: sizes,
bidId: bidRequest.bidId,
referer: bidderRequest.refererInfo.referer,
};

return {
method: 'POST',
url: ENDPOINT_URL,
data: payload
};
});
},

/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;

if (response) {
const bidResponse = {
requestId: response.requestId,
cpm: response.cpm,
currency: response.currency,
netRevenue: response.netRevenue,
width: response.width,
height: response.height,
creativeId: response.creativeId,
ttl: response.ttl,
ad: response.ad
};

bidResponses.push(bidResponse);
}

return bidResponses;
}
};

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

```
Module Name: Cointraffic Bidder Adapter
Module Type: Cointraffic Adapter
Maintainer: tech@cointraffic.io
```

# Description
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard. For additional information on this module, please contact us at ``support@cointraffic.io``.

# Test Parameters
```
var adUnits = [{
code: 'test-ad-div',
sizes: [[300, 250]],
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
bids: [{
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
}
}]
}];
```
125 changes: 125 additions & 0 deletions test/spec/modules/cointrafficBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { expect } from 'chai';
import { spec } from 'modules/cointrafficBidAdapter.js';

const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';

describe('cointrafficBidAdapter', function () {
describe('isBidRequestValid', function () {
let bid = {
bidder: 'cointraffic',
params: {
placementId: 'ct_testPlacementId'
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250]
],
bidId: 'bidId12345',
bidderRequestId: 'bidderRequestId12345',
auctionId: 'auctionId12345'
};

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

describe('buildRequests', function () {
let bidRequests = [
{
bidder: 'cointraffic',
params: {
placementId: 'ct_testPlacementId'
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250]
],
bidId: 'bidId12345',
bidderRequestId: 'bidderRequestId12345',
auctionId: 'auctionId12345',
},
{
bidder: 'cointraffic',
params: {
placementId: 'ct_testPlacementId'
},
adUnitCode: 'adunit-code2',
sizes: [
[300, 250]
],
bidId: 'bidId67890"',
bidderRequestId: 'bidderRequestId67890',
auctionId: 'auctionId12345',
}
];

let bidderRequests = {
refererInfo: {
numIframes: 0,
reachedTop: true,
referer: 'https://example.com',
stack: [
'https://example.com'
]
}
};

const request = spec.buildRequests(bidRequests, bidderRequests);

it('sends bid request to our endpoint via POST', function () {
expect(request[0].method).to.equal('POST');
expect(request[1].method).to.equal('POST');
});
it('attaches source and version to endpoint URL as query params', function () {
expect(request[0].url).to.equal(ENDPOINT_URL);
expect(request[1].url).to.equal(ENDPOINT_URL);
});
});

describe('interpretResponse', function () {
let bidRequest = [
{
method: 'POST',
url: ENDPOINT_URL,
data: {
placementId: 'ct_testPlacementId',
device: 'desktop',
sizes: ['300x250'],
bidId: 'bidId12345',
referer: 'www.example.com'
}
}
];

let serverResponse = {
body: {
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html> ',
}
};

it('should get the correct bid response', function () {
let expectedResponse = [{
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html>'
}];
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});
});
});