forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rtbsolutions * typos * cleanup * use ajax
- Loading branch information
1 parent
275ab3d
commit 0471175
Showing
3 changed files
with
290 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,100 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
import * as utils from '../src/utils'; | ||
import { ajax } from '../src/ajax'; | ||
|
||
const BIDDER_CODE = 'rtbsolutions'; | ||
const ENDPOINT_URL = 'https://dsp-eu-lb.rtbsolutions.pro/bid/hb'; | ||
|
||
export const spec = { | ||
version: '1.0', | ||
code: BIDDER_CODE, | ||
aliases: ['rtbss'], // short code | ||
nurls: {}, | ||
isBidRequestValid: function(bid) { | ||
return !!bid.params.blockId; | ||
}, | ||
buildRequests: function(validBidRequests, bidderRequest) { | ||
let req = []; | ||
|
||
bidderRequest.bids.forEach(item => { | ||
const width = item.sizes[0][0]; | ||
const height = item.sizes[0][1]; | ||
|
||
let imp = { | ||
referer: bidderRequest.refererInfo.referer, | ||
ua: navigator.userAgent, | ||
lang: this.getLanguage(), | ||
domain: this.getDomain(), | ||
width: width, | ||
height: height, | ||
type: 'banner', | ||
}; | ||
|
||
if (item.params.s1 !== undefined) imp.s1 = item.params.s1; | ||
if (item.params.s2 !== undefined) imp.s2 = item.params.s2; | ||
if (item.params.s3 !== undefined) imp.s3 = item.params.s3; | ||
if (item.params.s4 !== undefined) imp.s4 = item.params.s4; | ||
|
||
req.push({ | ||
bid_id: item.bidId, | ||
block_id: item.params.blockId, | ||
ver: this.version, | ||
imp | ||
}); | ||
}); | ||
|
||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: req, | ||
options: { | ||
contentType: 'application/json' | ||
} | ||
} | ||
}, | ||
interpretResponse: function(serverResponse, request) { | ||
const bidResponses = []; | ||
|
||
serverResponse.body.forEach(item => { | ||
this.nurls[item.bid_id] = item.nurl; | ||
|
||
const bidResponse = { | ||
requestId: item.bid_id, | ||
cpm: item.cpm, | ||
width: item.width, | ||
height: item.height, | ||
creativeId: item.creative_id, | ||
currency: item.currency, | ||
netRevenue: true, | ||
ttl: 360, | ||
ad: item.ad, | ||
}; | ||
|
||
bidResponses.push(bidResponse); | ||
}); | ||
|
||
return bidResponses; | ||
}, | ||
onBidWon: function(bid) { | ||
ajax(this.nurls[bid.requestId], null); | ||
}, | ||
|
||
getLanguage() { | ||
const language = navigator.language ? 'language' : 'userLanguage'; | ||
const lang2 = navigator[language].split('-')[0]; | ||
if (lang2.length === 2 || lang2.length === 3) { | ||
return lang2; | ||
} | ||
return ''; | ||
}, | ||
getDomain() { | ||
if (!utils.inIframe()) { | ||
return window.location.hostname | ||
} | ||
let origins = window.document.location.ancestorOrigins; | ||
if (origins && origins.length > 0) { | ||
return origins[origins.length - 1] | ||
} | ||
} | ||
}; | ||
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,128 @@ | ||
# Overview | ||
|
||
Module Name: Rtbsolutions Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
You can use this adapter to get a bid from rtbsolutions. | ||
|
||
About us: http://rtbsolutions.pro | ||
|
||
|
||
# Test Parameters | ||
```javascript | ||
var adUnits = [ | ||
{ | ||
code: '/19968336/header-bid-tag-1', | ||
mediaTypes: { | ||
banner: { | ||
sizes: sizes | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'rtbsolutions', | ||
params: { | ||
blockId: 777, | ||
s1: 'sub_1', | ||
s2: 'sub_2', | ||
s3: 'sub_3', | ||
s4: 'sub_4' | ||
} | ||
}] | ||
}]; | ||
``` | ||
|
||
Where: | ||
|
||
* blockId - Block ID from platform (required) | ||
* s1..s4 - Sub Id (optional) | ||
|
||
# Example page | ||
|
||
```html | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Prebid</title> | ||
<script async src="//www.googletagservices.com/tag/js/gpt.js"></script> | ||
<script async src="prebid.js"></script> | ||
<script> | ||
var sizes = [ | ||
[640, 480] | ||
]; | ||
var PREBID_TIMEOUT = 1000; | ||
var FAILSAFE_TIMEOUT = 3000; | ||
var adUnits = [ | ||
{ | ||
code: '/19968336/header-bid-tag-1', | ||
mediaTypes: { | ||
banner: { | ||
sizes: sizes | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'rtbsolutions', | ||
params: { | ||
blockId: 777 | ||
} | ||
}] | ||
}]; | ||
// ======== DO NOT EDIT BELOW THIS LINE =========== // | ||
var googletag = googletag || {}; | ||
googletag.cmd = googletag.cmd || []; | ||
googletag.cmd.push(function() { | ||
googletag.pubads().disableInitialLoad(); | ||
}); | ||
var pbjs = pbjs || {}; | ||
pbjs.que = pbjs.que || []; | ||
pbjs.que.push(function() { | ||
pbjs.addAdUnits(adUnits); | ||
pbjs.requestBids({ | ||
bidsBackHandler: initAdserver, | ||
timeout: PREBID_TIMEOUT | ||
}); | ||
}); | ||
function initAdserver() { | ||
if (pbjs.initAdserverSet) return; | ||
pbjs.initAdserverSet = true; | ||
googletag.cmd.push(function() { | ||
pbjs.setTargetingForGPTAsync && pbjs.setTargetingForGPTAsync(); | ||
googletag.pubads().refresh(); | ||
}); | ||
} | ||
// in case PBJS doesn't load | ||
setTimeout(function() { | ||
initAdserver(); | ||
}, FAILSAFE_TIMEOUT); | ||
googletag.cmd.push(function() { | ||
googletag.defineSlot('/19968336/header-bid-tag-1', sizes, 'div-1') | ||
.addService(googletag.pubads()); | ||
googletag.pubads().enableSingleRequest(); | ||
googletag.enableServices(); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<h1>Prebid</h1> | ||
<h5>Div-1</h5> | ||
<div id='div-1'> | ||
<script type='text/javascript'> | ||
googletag.cmd.push(function() { | ||
googletag.display('div-1'); | ||
}); | ||
</script> | ||
</div> | ||
</body> | ||
</html> | ||
``` |
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,62 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/rtbsolutionsBidAdapter'; | ||
|
||
describe('rtbsolutionsBidAdapterTests', function () { | ||
it('validate_pub_params_1', function () { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'rtbsolutions', | ||
params: { | ||
blockId: 777 | ||
} | ||
})).to.equal(true); | ||
}); | ||
it('validate_pub_params_2', function () { | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'rtbsolutions', | ||
params: { | ||
s1: 'test' | ||
} | ||
})).to.equal(false); | ||
}); | ||
it('validate_generated_params', function () { | ||
let bidderRequest = { | ||
bids: [], | ||
refererInfo: { | ||
referer: '' | ||
} | ||
}; | ||
bidderRequest.bids.push({ | ||
bidId: 'bid1234', | ||
bidder: 'rtbsolutions', | ||
params: {blockId: 777}, | ||
sizes: [[240, 400]] | ||
}); | ||
let request = spec.buildRequests(true, bidderRequest); | ||
let req_data = request.data[0]; | ||
expect(req_data.bid_id).to.equal('bid1234'); | ||
}); | ||
it('validate_response_params', function () { | ||
let serverResponse = { | ||
body: [{ | ||
ad: 'Ad html', | ||
bid_id: 'bid1234', | ||
cpm: 1, | ||
creative_id: 1, | ||
height: 480, | ||
nurl: 'http://test.test', | ||
width: 640, | ||
currency: 'USD', | ||
}] | ||
}; | ||
let bids = spec.interpretResponse(serverResponse); | ||
expect(bids).to.have.lengthOf(1); | ||
let bid = bids[0]; | ||
expect(bid.cpm).to.equal(1); | ||
expect(bid.currency).to.equal('USD'); | ||
expect(bid.width).to.equal(640); | ||
expect(bid.height).to.equal(480); | ||
expect(bid.netRevenue).to.equal(true); | ||
expect(bid.requestId).to.equal('bid1234'); | ||
expect(bid.ad).to.equal('Ad html'); | ||
}); | ||
}); |