-
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
Add ADSpend bidder adapter #3005
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5da6ee3
Add ADSpend bidder adapter
loorke d2ff195
Remove superfluous argument and fix bug with sizes
loorke bfabf69
Change bidder aliases
loorke 92a1112
Replace fetch with ajax from src/ajax.js
loorke d93b725
Store win event URL in memory, not in cookie
loorke 499ff26
Use getConfig(...) instead of nested access
loorke 1fa1e9a
Add sending multiple impressions to bidder
loorke 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,165 @@ | ||
import * as utils from 'src/utils'; | ||
import { ajax } from 'src/ajax' | ||
import { config } from 'src/config'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
import { BANNER } from 'src/mediaTypes'; | ||
|
||
const BIDDER_CODE = 'adspend'; | ||
const BID_URL = '//rtb.com.ru/headerbidding-bid'; | ||
const SYNC_URL = '//rtb.com.ru/headerbidding-sync?uid={UUID}'; | ||
const COOKIE_NAME = 'hb-adspend-id'; | ||
const UUID_LEN = 36; | ||
const TTL = 10000; | ||
const RUB = 'RUB'; | ||
const FIRST_PRICE = 1; | ||
const NET_REVENUE = true; | ||
|
||
const winEventURLs = {}; | ||
const placementToBidMap = {}; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['as'], | ||
supportedMediaTypes: [BANNER], | ||
|
||
onBidWon: function(winObj) { | ||
const requestId = winObj.requestId; | ||
const cpm = winObj.cpm; | ||
const event = winEventURLs[requestId].replace( | ||
/\$\{AUCTION_PRICE\}/, | ||
cpm | ||
); | ||
|
||
ajax(event, null); | ||
}, | ||
|
||
isBidRequestValid: function(bid) { | ||
const adServerCur = config.getConfig('currency.adServerCurrency') === RUB; | ||
|
||
return !!(adServerCur && | ||
bid.params && | ||
bid.params.bidfloor && | ||
bid.crumbs.pubcid && | ||
utils.checkCookieSupport() && | ||
utils.cookiesAreEnabled() | ||
); | ||
}, | ||
|
||
buildRequests: function(bidRequests, bidderRequest) { | ||
const req = bidRequests[Math.floor(Math.random() * bidRequests.length)]; | ||
const bidId = req.bidId; | ||
const at = FIRST_PRICE; | ||
const site = { id: req.crumbs.pubcid, domain: document.domain }; | ||
const device = { ua: navigator.userAgent, ip: '' }; | ||
const user = { id: getUserID() } | ||
const cur = [ RUB ]; | ||
const tmax = bidderRequest.timeout; | ||
|
||
const imp = bidRequests.map(req => { | ||
const params = req.params; | ||
|
||
const tagId = params.tagId; | ||
const id = params.placement; | ||
const banner = { 'format': getFormats(req.sizes) }; | ||
const bidfloor = params.bidfloor !== undefined | ||
? Number(params.bidfloor) : 1; | ||
const bidfloorcur = RUB; | ||
|
||
placementToBidMap[id] = bidId; | ||
|
||
return { | ||
id, | ||
tagId, | ||
banner, | ||
bidfloor, | ||
bidfloorcur, | ||
secure: 0, | ||
}; | ||
}); | ||
|
||
const payload = { | ||
bidId, | ||
at, | ||
site, | ||
device, | ||
user, | ||
imp, | ||
cur, | ||
tmax, | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: BID_URL, | ||
data: JSON.stringify(payload), | ||
}; | ||
}, | ||
|
||
interpretResponse: function(resp, {bidderRequest}) { | ||
if (resp.body === '') return []; | ||
|
||
const bids = resp.body.seatbid[0].bid.map(bid => { | ||
const cpm = bid.price; | ||
const impid = bid.impid; | ||
const requestId = placementToBidMap[impid]; | ||
const width = bid.w; | ||
const height = bid.h; | ||
const creativeId = bid.adid; | ||
const dealId = bid.dealid; | ||
const currency = resp.body.cur; | ||
const netRevenue = NET_REVENUE; | ||
const ttl = TTL; | ||
const ad = bid.adm; | ||
|
||
return { | ||
cpm, | ||
requestId, | ||
width, | ||
height, | ||
creativeId, | ||
dealId, | ||
currency, | ||
netRevenue, | ||
ttl, | ||
ad, | ||
}; | ||
}); | ||
|
||
return bids; | ||
}, | ||
|
||
getUserSyncs: function(syncOptions, resps) { | ||
let syncs = []; | ||
|
||
resps.forEach(resp => { | ||
if (syncOptions.pixelEnabled && resp.body === '') { | ||
const uuid = getUserID(); | ||
syncs.push({ | ||
type: 'image', | ||
url: SYNC_URL.replace('{UUID}', uuid), | ||
}); | ||
} | ||
}); | ||
|
||
return syncs | ||
} | ||
} | ||
|
||
const getUserID = () => { | ||
const i = document.cookie.indexOf(COOKIE_NAME); | ||
|
||
if (i === -1) { | ||
const uuid = utils.generateUUID(); | ||
document.cookie = `${COOKIE_NAME}=${uuid}; path=/`; | ||
return uuid; | ||
} | ||
|
||
const j = i + COOKIE_NAME.length + 1; | ||
return document.cookie.substring(j, j + UUID_LEN); | ||
}; | ||
|
||
const getFormats = arr => arr.map((s) => { | ||
return { w: s[0], h: s[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,60 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: AdSpend Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: gaffoonster@gmail.com | ||
``` | ||
|
||
# Description | ||
|
||
Connects to AdSpend bidder. | ||
AdSpend adapter supports only Banner at the moment. Video and Native will be add soon. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
// Banner | ||
{ | ||
code: 'div-gpt-ad-1460505748561-0', | ||
mediaTypes: { | ||
banner: { | ||
// You can choose one of them | ||
sizes: [ | ||
[300, 250], | ||
[300, 600], | ||
[240, 400], | ||
[728, 90], | ||
] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: "adspend", | ||
params: { | ||
bidfloor: 1, | ||
placement: 'test', | ||
tagId: 'test-ad', | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
|
||
pbjs.que.push(() => { | ||
pbjs.setConfig({ | ||
userSync: { | ||
syncEnabled: true, | ||
enabledBidders: ['adspend'], | ||
pixelEnabled: true, | ||
syncsPerBidder: 200, | ||
syncDelay: 100, | ||
}, | ||
currency: { | ||
adServerCurrency: 'RUB' // We work only with rubles for now | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
**It's a test banner, so you'll see some errors in console cause it will be trying to call our system's events.** |
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 please explain why you are only responding to random bid requests?
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.
I made some changes. Do you still have questions?