-
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.
Initial submission of Gamoshi's Gambid Bid Adapter
- Loading branch information
Showing
3 changed files
with
580 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,168 @@ | ||
import * as utils from 'src/utils'; | ||
import { registerBidder } from 'src/adapters/bidderFactory'; | ||
import { config } from 'src/config'; | ||
|
||
function getTopFrame() { | ||
try { | ||
return window.top === window ? 1 : 0; | ||
} catch (e) { | ||
return 0; | ||
} | ||
} | ||
|
||
function getTopWindowUrl() { | ||
try { | ||
return window.top.location.href; | ||
} catch (e) { | ||
utils.logMessage('Failed obtaining top window\'s URL: ', e); | ||
try { | ||
return window.location.href; | ||
} catch (e) { | ||
utils.logMessage('Failed obtaining current window\'s URL: ', e); | ||
return ''; | ||
} | ||
} | ||
} | ||
|
||
function getTopWindowDomain() { | ||
const url = getTopWindowUrl(); | ||
const domainStart = url.indexOf('://') + '://'.length; | ||
return url.substring(domainStart, url.indexOf('/', domainStart) < 0 ? url.length : url.indexOf('/', domainStart)); | ||
} | ||
|
||
function getTopWindowReferer() { | ||
try { | ||
return window.top.document.referrer; | ||
} catch (e) { | ||
utils.logMessage('Failed obtaining top window\'s referrer: ', e); | ||
try { | ||
return window.document.referrer; | ||
} catch (e) { | ||
utils.logMessage('Failed obtaining current window\'s referrer: ', e); | ||
return ''; | ||
} | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: 'gambid', | ||
aliases: [], | ||
supportedMediaTypes: [ 'banner', 'video' ], | ||
|
||
isBidRequestValid: function(bid) { | ||
return !!bid.params.supplyPartnerId && typeof bid.params.supplyPartnerId === 'string' && | ||
(typeof bid.params[ 'rtbEndpoint' ] === 'undefined' || typeof bid.params[ 'rtbEndpoint' ] === 'string') && | ||
(typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'number') && | ||
(typeof bid.params[ 'adpos' ] === 'undefined' || typeof bid.params[ 'adpos' ] === 'number') && | ||
(typeof bid.params[ 'protocols' ] === 'undefined' || Array.isArray(bid.params[ 'protocols' ])) && | ||
(typeof bid.params.instl === 'undefined' || bid.params.instl === 0 || bid.params.instl === 1); | ||
}, | ||
|
||
buildRequests: function(validBidRequests) { | ||
return validBidRequests.map(bidRequest => { | ||
const { adUnitCode, auctionId, mediaTypes, params, sizes, transactionId } = bidRequest; | ||
const baseEndpoint = params[ 'rtbEndpoint' ] || 'https://rtb.gambid.io'; | ||
const rtbEndpoint = `${baseEndpoint}/r/${params.supplyPartnerId}/bidr?rformat=open_rtb&bidder=prebid&` + params.query || ''; | ||
const rtbBidRequest = { | ||
'id': auctionId, | ||
'site': { | ||
'domain': getTopWindowDomain(), | ||
'page': config.getConfig('pageUrl') || utils.getTopWindowUrl(), | ||
'ref': getTopWindowReferer() | ||
}, | ||
'device': { | ||
'ua': navigator.userAgent | ||
}, | ||
'imp': [] | ||
}; | ||
|
||
const imp = { | ||
'id': transactionId, | ||
'instl': params.instl === 1 ? 1 : 0, | ||
'tagid': adUnitCode, | ||
'bidfloor': params.bidfloor || 0, | ||
'bidfloorcur': 'USD', | ||
'secure': getTopWindowUrl().toLowerCase().startsWith('http://') ? 0 : 1 | ||
}; | ||
|
||
if (!mediaTypes || mediaTypes.banner) { | ||
imp.banner = { | ||
w: sizes.length ? sizes[ 0 ][ 0 ] : 300, | ||
h: sizes.length ? sizes[ 0 ][ 1 ] : 250, | ||
pos: params.pos || 0, | ||
topframe: getTopFrame() | ||
}; | ||
} else if (mediaTypes && mediaTypes.video) { | ||
imp.video = { | ||
w: sizes.length ? sizes[ 0 ][ 0 ] : 300, | ||
h: sizes.length ? sizes[ 0 ][ 1 ] : 250, | ||
protocols: params.protocols || [1, 2, 3, 4, 5, 6], | ||
pos: params.pos || 0, | ||
topframe: getTopFrame() | ||
}; | ||
} else { | ||
return; | ||
} | ||
rtbBidRequest.imp.push(imp); | ||
return { method: 'POST', url: rtbEndpoint, data: rtbBidRequest, bidRequest }; | ||
}); | ||
}, | ||
|
||
interpretResponse: function(serverResponse, bidRequest) { | ||
const response = serverResponse && serverResponse.body; | ||
if (!response) { | ||
utils.logError('empty response'); | ||
return []; | ||
} | ||
|
||
const bids = response.seatbid.reduce((acc, seatBid) => acc.concat(seatBid.bid), []); | ||
const outBids = []; | ||
bids.forEach(bid => { | ||
const outBid = { | ||
requestId: bidRequest.bidRequest.bidId, | ||
cpm: bid.price, | ||
width: bid.w, | ||
height: bid.h, | ||
ttl: 60 * 10, | ||
creativeId: bid.crid, | ||
netRevenue: true, | ||
currency: bid.cur || response.cur | ||
}; | ||
if (!bidRequest.bidRequest.mediaTypes || bidRequest.bidRequest.mediaTypes.banner) { | ||
outBids.push(Object.assign({}, outBid, { ad: bid.adm })); | ||
} else if ( bidRequest.bidRequest.mediaTypes && bidRequest.bidRequest.mediaTypes.video) { | ||
outBids.push(Object.assign({}, outBid, { vastXml: bid.adm })); | ||
} | ||
}); | ||
return outBids; | ||
}, | ||
|
||
getUserSyncs: function(syncOptions, serverResponses) { | ||
const syncs = []; | ||
serverResponses.forEach(resp => { | ||
if (resp.body) { | ||
const bidResponse = resp.body; | ||
if (bidResponse.ext && Array.isArray(bidResponse.ext[ 'utrk' ])) { | ||
bidResponse.ext[ 'utrk' ].forEach(pixel => syncs.push({ type: pixel.type, url: pixel.url })); | ||
} | ||
if (Array.isArray(bidResponse.seatbid)) { | ||
bidResponse.seatbid.forEach(seatBid => { | ||
if (Array.isArray(seatBid.bid)) { | ||
seatBid.bid.forEach(bid => { | ||
if (bid.ext && Array.isArray(bid.ext[ 'utrk' ])) { | ||
bid.ext[ 'utrk' ].forEach(pixel => syncs.push({ type: pixel.type, url: pixel.url })); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
return syncs; | ||
}, | ||
|
||
onTimeout: function(data) { | ||
utils.logWarn('Gambid request timed out.', data); | ||
} | ||
}; | ||
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,81 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Gamoshi's Gambid Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: arik@gamoshi.com | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Gamoshi's Gambid platform & exchange for bids. | ||
|
||
Gambid bid adapter supports Banner & Outstream Video. The *only* required parameter (in the `params` section) is the `supplyPartnerId` parameter. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
// Banner adUnit | ||
{ | ||
code: 'banner-div', | ||
sizes: [[300, 250], [300,600]], | ||
bids: [{ | ||
bidder: 'gambid', | ||
params: { | ||
// ID of the supply partner you created in the Gambid dashboard | ||
supplyPartnerId: '12345', | ||
// OPTIONAL: if you have a whitelabel account on Gamoshi, specify it here | ||
rtbEndpoint: 'https://my.custom-whitelabel-domain.io', | ||
// OPTIONAL: custom bid floor | ||
bidfloor: 0.03, | ||
// OPTIONAL: if you know the ad position on the page, specify it here | ||
// (this corresponds to "Ad Position" in OpenRTB 2.3, section 5.4) | ||
adpos: 1, | ||
// OPTIONAL: whether this is an interstitial placement (0 or 1) | ||
// (see "instl" property in "Imp" object in the OpenRTB 2.3, section 3.2.2) | ||
instl: 0 | ||
} | ||
}] | ||
}, | ||
// Video outstream adUnit | ||
{ | ||
code: 'video-outstream', | ||
sizes: [[640, 480]], | ||
mediaTypes: { | ||
video: { | ||
context: 'outstream', | ||
playerSize: [640, 480] | ||
} | ||
}, | ||
bids: [ { | ||
bidder: 'gambid', | ||
params: { | ||
// ID of the supply partner you created in the Gambid dashboard | ||
supplyPartnerId: '12345', | ||
// OPTIONAL: if you have a whitelabel account on Gamoshi, specify it here | ||
rtbEndpoint: 'https://my.custom-whitelabel-domain.io', | ||
// OPTIONAL: custom bid floor | ||
bidfloor: 0.03, | ||
// OPTIONAL: if you know the ad position on the page, specify it here | ||
// (this corresponds to "Ad Position" in OpenRTB 2.3, section 5.4) | ||
adpos: 1, | ||
// OPTIONAL: whether this is an interstitial placement (0 or 1) | ||
// (see "instl" property in "Imp" object in the OpenRTB 2.3, section 3.2.2) | ||
instl: 0 | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.