-
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
HypeLab Bid Adapter: Initial Release #10003
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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,153 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { generateUUID } from '../src/utils.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
|
||
export const BIDDER_CODE = 'hypelab'; | ||
export const ENDPOINT_URL = 'https://api.hypelab.com'; | ||
|
||
export const REQUEST_ROUTE = '/v1/prebid_requests'; | ||
export const EVENT_ROUTE = '/v1/events'; | ||
export const REPORTING_ROUTE = ''; | ||
|
||
const PREBID_VERSION = '$prebid.version$'; | ||
const PROVIDER_NAME = 'prebid'; | ||
const PROVIDER_VERSION = '0.0.1'; | ||
|
||
const url = (route) => ENDPOINT_URL + route; | ||
|
||
export function mediaSize(data) { | ||
if (!data || !data.creative_set) return { width: 0, height: 0 }; | ||
const media = data.creative_set.video || data.creative_set.image || {}; | ||
return { width: media.width, height: media.height }; | ||
} | ||
|
||
function isBidRequestValid(bidderRequest) { | ||
return ( | ||
!!bidderRequest.params?.property_slug && | ||
!!bidderRequest.params?.placement_slug | ||
); | ||
} | ||
|
||
function buildRequests(validBidRequests, bidderRequest) { | ||
const result = validBidRequests.map((request) => { | ||
const uids = (request.userIdAsEids || []).reduce((a, c) => { | ||
const ids = c.uids.map((uid) => uid.id); | ||
return [...a, ...ids]; | ||
}, []); | ||
|
||
const uuid = uids[0] ? uids[0] : generateTemporaryUUID(); | ||
|
||
const payload = { | ||
property_slug: request.params.property_slug, | ||
placement_slug: request.params.placement_slug, | ||
provider_version: PROVIDER_VERSION, | ||
provider_name: PROVIDER_NAME, | ||
referrer: | ||
bidderRequest.refererInfo?.page || typeof window != 'undefined' | ||
? window.location.href | ||
: '', | ||
sdk_version: PREBID_VERSION, | ||
sizes: request.sizes, | ||
wids: [], | ||
uuid, | ||
bidRequestsCount: request.bidRequestsCount, | ||
bidderRequestsCount: request.bidderRequestsCount, | ||
bidderWinsCount: request.bidderWinsCount, | ||
wp: { | ||
ada: typeof window != 'undefined' && !!window.cardano, | ||
bnb: typeof window != 'undefined' && !!window.BinanceChain, | ||
eth: typeof window != 'undefined' && !!window.ethereum, | ||
sol: typeof window != 'undefined' && !!window.solana, | ||
tron: typeof window != 'undefined' && !!window.tron, | ||
}, | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: url(REQUEST_ROUTE), | ||
options: { contentType: 'application/json', withCredentials: false }, | ||
data: payload, | ||
bidId: request.bidId, | ||
}; | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
function generateTemporaryUUID() { | ||
return 'tmp_' + generateUUID(); | ||
} | ||
|
||
function interpretResponse(serverResponse, bidRequest) { | ||
const { data } = serverResponse.body; | ||
|
||
if (!data.cpm || !data.html) return []; | ||
|
||
const size = mediaSize(data); | ||
|
||
const result = { | ||
requestId: bidRequest.bidId, | ||
cpm: data.cpm, | ||
width: size.width, | ||
height: size.height, | ||
creativeId: data.creative_set_slug, | ||
currency: data.currency, | ||
netRevenue: true, | ||
referrer: bidRequest.data.referrer, | ||
ttl: data.ttl, | ||
ad: data.html, | ||
mediaType: serverResponse.body.data.media_type, | ||
meta: { | ||
advertiserDomains: data.advertiserDomains || [], | ||
}, | ||
}; | ||
|
||
return [result]; | ||
} | ||
|
||
export function report(eventType, data, route = REPORTING_ROUTE) { | ||
if (!route) return; | ||
|
||
const options = { | ||
method: 'POST', | ||
contentType: 'application/json', | ||
withCredentials: true, | ||
}; | ||
|
||
const request = { type: eventType, data }; | ||
ajax(url(route), null, request, options); | ||
} | ||
|
||
function onTimeout(timeoutData) { | ||
this.report('timeout', timeoutData); | ||
} | ||
|
||
function onBidWon(bid) { | ||
this.report('bidWon', bid); | ||
} | ||
|
||
function onSetTargeting(bid) { | ||
this.report('setTargeting', bid); | ||
} | ||
|
||
function onBidderError(errorData) { | ||
this.report('bidderError', errorData); | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
aliases: ['hype'], | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
onTimeout, | ||
onBidWon, | ||
onSetTargeting, | ||
onBidderError, | ||
report, | ||
REPORTING_ROUTE: 'a', | ||
}; | ||
|
||
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,38 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: HypeLab Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Prebid.JS adapter that connects to HypeLab ad network for bids. | ||
*NOTE*: The HypeLab Adapter requires setup and approval before use. Please reach out to `[email protected]` for more details. To get started, replace the `property_slug` with your property_slug and the `placement_slug` with your placement slug to receive bids. The placement slug will depend on the required size and can be set via the HypeLab interface. | ||
|
||
# Test Parameters | ||
|
||
## Sample Banner Ad Unit | ||
|
||
```js | ||
var adUnits = [ | ||
{ | ||
code: 'banner-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[728, 90]], | ||
}, | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'hypelab', | ||
params: { | ||
property_slug: 'prebid', | ||
placement_slug: 'test_placement' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
``` |
Oops, something went wrong.
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.
I'm not sure if a bid adapter is allowed to make external ajax calls. I'm checking with others on this but according to me, having an analytics adapter or a separate integration with an analytics provider is more appropriate.
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.
Got it. Let me know what you find. Here are a few other places where ajax POST requests are being used to record onBidWon and other callbacks:
Prebid.js/modules/adpartnerBidAdapter.js
Line 140 in 222c702
Prebid.js/modules/gnetBidAdapter.js
Line 107 in 222c702
Prebid.js/modules/datablocksBidAdapter.js
Line 190 in 222c702