-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Feat/rtbsolutions #4556
Merged
Merged
Feat/rtbsolutions #4556
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,99 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
import * as utils from '../src/utils'; | ||
|
||
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) { | ||
fetch(this.nurls[bid.requestId]) | ||
}, | ||
|
||
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'); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the
ajax
interface fromsrc/ajax.js
instead of thefetch
here to make your follow-up call to your endpoint? Prebid.js doesn't support Promises at this time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jsnellbaker , thanks for your review, we have submitted the update