-
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.
- Loading branch information
Showing
2 changed files
with
216 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,158 @@ | ||
import * as utils from 'src/utils'; | ||
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 COOKIE_EXPIRE = 600; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['adspend'], | ||
supportedMediaTypes: [BANNER], | ||
|
||
onBidWon: function(winObj) { | ||
const requestId = winObj.requestId; | ||
const cpm = winObj.cpm; | ||
const event = getWinEvent(requestId).replace(/\$\{AUCTION_PRICE\}/, cpm); | ||
|
||
fetch(event); | ||
}, | ||
|
||
isBidRequestValid: function(bid) { | ||
const conf = config.getConfig(); | ||
return !!(conf.currency && | ||
conf.currency.adServerCurrency && | ||
bid.crumbs.pubcid && | ||
utils.checkCookieSupport() && | ||
utils.cookiesAreEnabled() | ||
); | ||
}, | ||
|
||
buildRequests: function(bidRequests, bidderRequest) { | ||
console.log('DEBUG 1'); | ||
console.log(bidRequests); | ||
console.log(bidderRequest); | ||
|
||
const req = bidRequests[Math.floor(Math.random() * bidRequests.length)]; | ||
|
||
const conf = config.getConfig(); | ||
const cur = conf.currency.adServerCurrency; | ||
|
||
const bidfloor = req.params.bidfloor; | ||
|
||
const payload = { | ||
'id': req.bidId, | ||
'site': { | ||
'id': req.crumbs.pubcid, | ||
'domain': document.domain | ||
}, | ||
'device': { | ||
'ua': navigator.userAgent, | ||
'ip': '' | ||
}, | ||
'user': { 'id': getUserID(document.cookie) }, | ||
'imp': [ | ||
{ | ||
'id': req.params.placement, | ||
'tagId': req.params.tagId, | ||
'banner': { 'format': getFormats(req.sizes) }, | ||
'bidfloor': bidfloor !== undefined ? Number(bidfloor) : 1, | ||
'bidfloorcur': cur, | ||
'secure': 0 | ||
} | ||
], | ||
'cur': [ | ||
cur | ||
], | ||
'tmax': bidderRequest.timeout | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: BID_URL, | ||
data: JSON.stringify(payload), | ||
}; | ||
}, | ||
|
||
interpretResponse: function(resp, {bidderRequest}) { | ||
alert('Hello, world!'); | ||
console.log('DEBUG 2'); | ||
console.log(resp); | ||
|
||
const bids = []; | ||
|
||
if (resp.body === '') return bids; | ||
|
||
const respBid = resp.body.seatbid[0].bid[0]; | ||
const requestId = resp.body.id; | ||
|
||
document.cookie = | ||
`on_win_event__${requestId}=${respBid.nurl}; max-age=${COOKIE_EXPIRE}`; | ||
|
||
const bid = { | ||
cpm: respBid.price, | ||
requestId: resp.body.id, | ||
width: 300, | ||
height: 250, | ||
creativeId: respBid.adid, | ||
dealId: respBid.dealid, | ||
currency: resp.body.cur, | ||
netRevenue: true, | ||
ttl: 10000, | ||
ad: respBid.adm | ||
}; | ||
|
||
bids.push(bid); | ||
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 getWinEvent = (requestId) => { | ||
const cookieName = `on_win_event__${requestId}`; | ||
const event = document.cookie | ||
.split(';') | ||
.find(item => item.includes(cookieName)) | ||
.split(`${cookieName}=`)[1]; | ||
|
||
return event; | ||
}; | ||
|
||
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,58 @@ | ||
# 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: 'any_code', | ||
mediaTypes: { | ||
banner: { | ||
// You can choose one of them | ||
sizes: [ | ||
[300, 250], | ||
[300, 600], | ||
[240, 400], | ||
[728, 90], | ||
] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: "adspend", | ||
params: { | ||
// These params is required for getting test banner | ||
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 | ||
} | ||
}); | ||
}); | ||
``` |