-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New adapter "Cointraffic" added (#5695)
* New adapter "Cointraffic" added * removed mobile detection * The sizes property has been updated, added supportedMediaTypes.
- Loading branch information
Showing
3 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as utils from '../src/utils.js'; | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import {BANNER} from '../src/mediaTypes.js' | ||
|
||
const BIDDER_CODE = 'cointraffic'; | ||
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
|
||
/** | ||
* 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) { | ||
return validBidRequests.map(bidRequest => { | ||
const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes); | ||
|
||
const payload = { | ||
placementId: bidRequest.params.placementId, | ||
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 (utils.isEmpty(response)) { | ||
return bidResponses; | ||
} | ||
|
||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Cointraffic Bidder Adapter | ||
Module Type: Cointraffic Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# 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 ``[email protected]``. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [{ | ||
code: 'test-ad-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'cointraffic', | ||
params: { | ||
placementId: 'testPlacementId' | ||
} | ||
}] | ||
}]; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
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: '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: 'testPlacementId' | ||
}, | ||
adUnitCode: 'adunit-code', | ||
sizes: [ | ||
[300, 250] | ||
], | ||
bidId: 'bidId12345', | ||
bidderRequestId: 'bidderRequestId12345', | ||
auctionId: 'auctionId12345', | ||
}, | ||
{ | ||
bidder: 'cointraffic', | ||
params: { | ||
placementId: '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: 'testPlacementId', | ||
device: 'desktop', | ||
sizes: ['300x250'], | ||
bidId: 'bidId12345', | ||
referer: 'www.example.com' | ||
} | ||
} | ||
]; | ||
|
||
it('should get the correct bid response', function () { | ||
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> ', | ||
} | ||
}; | ||
|
||
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)); | ||
}); | ||
|
||
it('should get empty bid response if server response body is empty', function () { | ||
let serverResponse = { | ||
body: {} | ||
}; | ||
|
||
let expectedResponse = []; | ||
|
||
let result = spec.interpretResponse(serverResponse, bidRequest[0]); | ||
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); | ||
}); | ||
|
||
it('should get empty bid response if no server response', function () { | ||
let serverResponse = {}; | ||
|
||
let expectedResponse = []; | ||
|
||
let result = spec.interpretResponse(serverResponse, bidRequest[0]); | ||
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); | ||
}); | ||
}); | ||
}); |