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.
Bidphysics Bid Adapter (prebid#3666)
* Bidphysics Bid Adapter * BidPhysics bid-adapter tests fix * removed empty functions * minor update - added publisherId and networkId params
- Loading branch information
1 parent
7aae8df
commit ae0f5f6
Showing
3 changed files
with
428 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,134 @@ | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
import * as utils from '../src/utils'; | ||
import {BANNER} from '../src/mediaTypes'; | ||
|
||
const ENDPOINT_URL = '//exchange.bidphysics.com/auction'; | ||
|
||
const DEFAULT_BID_TTL = 30; | ||
const DEFAULT_CURRENCY = 'USD'; | ||
const DEFAULT_NET_REVENUE = true; | ||
|
||
export const spec = { | ||
code: 'bidphysics', | ||
aliases: ['yieldlift', 'padsquad'], | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: function (bid) { | ||
return (!!bid.params.unitId && typeof bid.params.unitId === 'string') || | ||
(!!bid.params.networkId && typeof bid.params.networkId === 'string') || | ||
(!!bid.params.publisherId && typeof bid.params.publisherId === 'string'); | ||
}, | ||
|
||
buildRequests: function (validBidRequests, bidderRequest) { | ||
if (!validBidRequests || !bidderRequest) { | ||
return; | ||
} | ||
const publisherId = validBidRequests[0].params.publisherId; | ||
const networkId = validBidRequests[0].params.networkId; | ||
const impressions = validBidRequests.map(bidRequest => ({ | ||
id: bidRequest.bidId, | ||
banner: { | ||
format: bidRequest.sizes.map(sizeArr => ({ | ||
w: sizeArr[0], | ||
h: sizeArr[1] | ||
})) | ||
}, | ||
ext: { | ||
bidphysics: { | ||
unitId: bidRequest.params.unitId | ||
} | ||
} | ||
})); | ||
|
||
const openrtbRequest = { | ||
id: bidderRequest.auctionId, | ||
imp: impressions, | ||
site: { | ||
domain: window.location.hostname, | ||
page: window.location.href, | ||
ref: bidderRequest.refererInfo ? bidderRequest.refererInfo.referer || null : null | ||
}, | ||
ext: { | ||
bidphysics: { | ||
publisherId: publisherId, | ||
networkId: networkId, | ||
} | ||
} | ||
}; | ||
|
||
// apply gdpr | ||
if (bidderRequest.gdprConsent) { | ||
openrtbRequest.regs = {ext: {gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0}}; | ||
openrtbRequest.user = {ext: {consent: bidderRequest.gdprConsent.consentString}}; | ||
} | ||
|
||
const payloadString = JSON.stringify(openrtbRequest); | ||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: payloadString, | ||
}; | ||
}, | ||
|
||
interpretResponse: function (serverResponse, request) { | ||
const bidResponses = []; | ||
const response = (serverResponse || {}).body; | ||
// response is always one seat (bidphysics) with (optional) bids for each impression | ||
if (response && response.seatbid && response.seatbid.length === 1 && response.seatbid[0].bid && response.seatbid[0].bid.length) { | ||
response.seatbid[0].bid.forEach(bid => { | ||
bidResponses.push({ | ||
requestId: bid.impid, | ||
cpm: bid.price, | ||
width: bid.w, | ||
height: bid.h, | ||
ad: bid.adm, | ||
ttl: DEFAULT_BID_TTL, | ||
creativeId: bid.crid, | ||
netRevenue: DEFAULT_NET_REVENUE, | ||
currency: DEFAULT_CURRENCY, | ||
}) | ||
}) | ||
} else { | ||
utils.logInfo('bidphysics.interpretResponse :: no valid responses to interpret'); | ||
} | ||
return bidResponses; | ||
}, | ||
getUserSyncs: function (syncOptions, serverResponses) { | ||
utils.logInfo('bidphysics.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses); | ||
let syncs = []; | ||
|
||
if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { | ||
return syncs; | ||
} | ||
|
||
serverResponses.forEach(resp => { | ||
const userSync = utils.deepAccess(resp, 'body.ext.usersync'); | ||
if (userSync) { | ||
let syncDetails = []; | ||
Object.keys(userSync).forEach(key => { | ||
const value = userSync[key]; | ||
if (value.syncs && value.syncs.length) { | ||
syncDetails = syncDetails.concat(value.syncs); | ||
} | ||
}); | ||
syncDetails.forEach(syncDetails => { | ||
syncs.push({ | ||
type: syncDetails.type === 'iframe' ? 'iframe' : 'image', | ||
url: syncDetails.url | ||
}); | ||
}); | ||
|
||
if (!syncOptions.iframeEnabled) { | ||
syncs = syncs.filter(s => s.type !== 'iframe') | ||
} | ||
if (!syncOptions.pixelEnabled) { | ||
syncs = syncs.filter(s => s.type !== 'image') | ||
} | ||
} | ||
}); | ||
utils.logInfo('bidphysics.getUserSyncs result=%o', syncs); | ||
return syncs; | ||
}, | ||
|
||
}; | ||
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,33 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: BidPhysics Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: info@bidphysics.com | ||
``` | ||
|
||
# Description | ||
|
||
Connects to BidPhysics exchange for bids. | ||
|
||
BidPhysics bid adapter supports Banner ads. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'banner-ad-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250], [300,600]] | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'bidphysics', | ||
params: { | ||
unitId: 'bidphysics-test' | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.