-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update GetIntent adapter to 1.0 version #1721
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3a332fa
AD-2311: Make GetIntent adapter compatible with Prebid.js 1.0 version
kprokopchik 6d22ab4
AD-2311: remove blank line
kprokopchik d5c27ee
Trigger
kprokopchik 53c946f
GetIntent adapter - added bid response fields: currency, ttl and netR…
kprokopchik 359c16a
GetIntent adapter - added bid response fields: bidId, creativeId (#1721)
kprokopchik 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 hidden or 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 |
|---|---|---|
| @@ -1,78 +1,143 @@ | ||
| import { STATUS } from 'src/constants'; | ||
| import adaptermanager from 'src/adaptermanager'; | ||
| import { registerBidder } from 'src/adapters/bidderFactory'; | ||
|
|
||
| var bidfactory = require('src/bidfactory.js'); | ||
| var bidmanager = require('src/bidmanager.js'); | ||
| var adloader = require('src/adloader.js'); | ||
| const BIDDER_CODE = 'getintent'; | ||
| const IS_NET_REVENUE = true; | ||
| const BID_HOST = 'px.adhigh.net'; | ||
| const BID_BANNER_PATH = '/rtb/direct_banner'; | ||
| const BID_VIDEO_PATH = '/rtb/direct_vast'; | ||
| const BID_RESPONSE_TTL_SEC = 360; | ||
| const VIDEO_PROPERTIES = [ | ||
| 'protocols', 'mimes', 'min_dur', 'max_dur', 'min_btr', 'max_btr', 'vi_format', 'api', 'skippable' | ||
| ]; | ||
| const OPTIONAL_PROPERTIES = [ | ||
| 'cur', 'floor' | ||
| ]; | ||
|
|
||
| var GetIntentAdapter = function GetIntentAdapter() { | ||
| var headerBiddingStaticJS = window.location.protocol + '//cdn.adhigh.net/adserver/hb.js'; | ||
| export const spec = { | ||
| code: BIDDER_CODE, | ||
| aliases: ['getintentAdapter'], | ||
| supportedMediaTypes: ['video', 'banner'], | ||
|
|
||
| function _callBids(params) { | ||
| if (typeof window.gi_hb === 'undefined') { | ||
| adloader.loadScript(headerBiddingStaticJS, function() { | ||
| bid(params); | ||
| }, true); | ||
| } else { | ||
| bid(params); | ||
| /** | ||
| * Determines whether or not the given bid request is valid. | ||
| * | ||
| * @param {BidRequest} bid The bid to validate. | ||
| * @return {boolean} True if this is a valid bid, and false otherwise. | ||
| * */ | ||
| isBidRequestValid: function(bid) { | ||
| return !!(bid && bid.params && bid.params.pid && bid.params.tid); | ||
| }, | ||
|
|
||
| /** | ||
| * Make a server request from the list of BidRequests. | ||
| * | ||
| * @param {BidRequest[]} bidRequests - an array of bids. | ||
| * @return ServerRequest[] | ||
| */ | ||
| buildRequests: function(bidRequests) { | ||
| return bidRequests.map(bidRequest => { | ||
| let giBidRequest = buildGiBidRequest(bidRequest); | ||
| return { | ||
| method: 'GET', | ||
| url: buildUrl(giBidRequest), | ||
| data: giBidRequest, | ||
| }; | ||
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Callback for bids, after the call to DSP completes. | ||
| * Parse the response from the server into a list of bids. | ||
| * | ||
| * @param {object} serverResponse A response from the server. | ||
| * @return {Bid[]} An array of bids which were nested inside the server. | ||
| */ | ||
| interpretResponse: function(serverResponse) { | ||
| let responseBody = serverResponse.body; | ||
| const bids = []; | ||
| if (responseBody && responseBody.no_bid !== 1) { | ||
| let size = parseSize(responseBody.size); | ||
| let bid = { | ||
| requestId: responseBody.bid_id, | ||
| ttl: BID_RESPONSE_TTL_SEC, | ||
| netRevenue: IS_NET_REVENUE, | ||
| currency: responseBody.currency, | ||
| creativeId: responseBody.creative_id, | ||
| cpm: responseBody.cpm, | ||
| width: size[0], | ||
| height: size[1] | ||
| }; | ||
| if (responseBody.vast_url) { | ||
| bid.mediaType = 'video'; | ||
| bid.vastUrl = responseBody.vast_url; | ||
| } else { | ||
| bid.mediaType = 'banner'; | ||
| bid.ad = responseBody.ad; | ||
| } | ||
| bids.push(bid); | ||
| } | ||
| return bids; | ||
| } | ||
|
|
||
| function addOptional(params, request, props) { | ||
| for (var i = 0; i < props.length; i++) { | ||
| if (params.hasOwnProperty(props[i])) { | ||
| request[props[i]] = params[props[i]]; | ||
| } | ||
|
|
||
| function buildUrl(bid) { | ||
| return '//' + BID_HOST + (bid.is_video ? BID_VIDEO_PATH : BID_BANNER_PATH); | ||
| } | ||
|
|
||
| /** | ||
| * Builds GI bid request from BidRequest. | ||
| * | ||
| * @param {BidRequest} bidRequest. | ||
| * @return {object} GI bid request. | ||
| * */ | ||
| function buildGiBidRequest(bidRequest) { | ||
| let giBidRequest = { | ||
| bid_id: bidRequest.bidId, | ||
| pid: bidRequest.params.pid, // required | ||
| tid: bidRequest.params.tid, // required | ||
| known: bidRequest.params.known || 1, | ||
| is_video: bidRequest.mediaType === 'video', | ||
| resp_type: 'JSON' | ||
| }; | ||
| if (bidRequest.sizes) { | ||
| giBidRequest.size = produceSize(bidRequest.sizes); | ||
| } | ||
| addVideo(bidRequest.params.video, giBidRequest); | ||
| addOptional(bidRequest.params, giBidRequest, OPTIONAL_PROPERTIES); | ||
| return giBidRequest; | ||
| } | ||
|
|
||
| function addVideo(video, giBidRequest) { | ||
| if (giBidRequest.is_video && video) { | ||
| for (let i = 0, l = VIDEO_PROPERTIES.length; i < l; i++) { | ||
| let key = VIDEO_PROPERTIES[i]; | ||
| if (video.hasOwnProperty(key)) { | ||
| giBidRequest[key] = Array.isArray(video[key]) ? video[key].join(',') : video[key]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function bid(params) { | ||
| var bids = params.bids || []; | ||
| for (var i = 0; i < bids.length; i++) { | ||
| var bidRequest = bids[i]; | ||
| var request = { | ||
| pid: bidRequest.params.pid, // required | ||
| tid: bidRequest.params.tid, // required | ||
| known: bidRequest.params.known || 1, | ||
| is_video: bidRequest.mediaType === 'video', | ||
| video: bidRequest.params.video || {}, | ||
| size: bidRequest.sizes[0].join('x'), | ||
| }; | ||
| addOptional(bidRequest.params, request, ['cur', 'floor']); | ||
| (function (r, br) { | ||
| window.gi_hb.makeBid(r, function(bidResponse) { | ||
| if (bidResponse.no_bid === 1) { | ||
| var nobid = bidfactory.createBid(STATUS.NO_BID); | ||
| nobid.bidderCode = br.bidder; | ||
| bidmanager.addBidResponse(br.placementCode, nobid); | ||
| } else { | ||
| var bid = bidfactory.createBid(STATUS.GOOD); | ||
| var size = bidResponse.size.split('x'); | ||
| bid.bidderCode = br.bidder; | ||
| bid.cpm = bidResponse.cpm; | ||
| bid.width = size[0]; | ||
| bid.height = size[1]; | ||
| if (br.mediaType === 'video') { | ||
| bid.vastUrl = bidResponse.vast_url; | ||
| bid.descriptionUrl = bidResponse.vast_url; | ||
| bid.mediaType = 'video'; | ||
| } else { | ||
| bid.ad = bidResponse.ad; | ||
| } | ||
| bidmanager.addBidResponse(br.placementCode, bid); | ||
| } | ||
| }); | ||
| })(request, bidRequest); | ||
| function addOptional(params, request, props) { | ||
| for (let i = 0; i < props.length; i++) { | ||
| if (params.hasOwnProperty(props[i])) { | ||
| request[props[i]] = params[props[i]]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| callBids: _callBids | ||
| }; | ||
| }; | ||
| function parseSize(s) { | ||
| return s.split('x').map(Number); | ||
| } | ||
|
|
||
| adaptermanager.registerBidAdapter(new GetIntentAdapter(), 'getintent', { | ||
| supportedMediaTypes: ['video'] | ||
| }); | ||
| function produceSize(sizes) { | ||
| // TODO: add support for multiple sizes | ||
| if (Array.isArray(sizes[0])) { | ||
| return sizes[0].join('x'); | ||
| } else { | ||
| return sizes.join('x'); | ||
| } | ||
| } | ||
|
|
||
| module.exports = GetIntentAdapter; | ||
| registerBidder(spec); | ||
This file contains hidden or 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,48 @@ | ||
| # Overview | ||
|
|
||
| ``` | ||
| Module Name: GetIntent Bidder Adapter | ||
| Module Type: Bidder Adapter | ||
| Maintainer: server-dev@getintent.com | ||
| ``` | ||
|
|
||
| # Description | ||
|
|
||
| Module that connects to GetIntent's demand sources. | ||
| Banner and Video formats are supported. | ||
|
|
||
| # Required parameters | ||
| * ```pid``` for Publisher ID | ||
| * ```tid``` for Tag ID. | ||
|
|
||
| # Test Parameters | ||
| ``` | ||
| var adUnits = [ | ||
| { | ||
| code: 'test-ad', | ||
| sizes: [[300, 250]], | ||
| bids: [ | ||
| { | ||
| bidder: "getintent", | ||
| params: { | ||
| pid: "7", | ||
| tid: "test01" | ||
| } | ||
| } | ||
| ] | ||
| },{ | ||
| code: 'test-video-ad', | ||
| sizes: [[300, 250]], | ||
| bids: [ | ||
| { | ||
| bidder: "getintent", | ||
| params: { | ||
| pid: "7", | ||
| tid: "test01" | ||
| }, | ||
| mediaType: "video" | ||
| } | ||
| ] | ||
| } | ||
| ]; | ||
| ``` |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This should set
bidId: bidRequest.bidIdso that theinterpretResponsefunction has access to it