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.
* Adding Konduit module * Removed superfluous arguments passed to obtainVastUrl function * Removed superfluous arguments passed to obtainVastUrl function. * Build trigger (empty commit) * Module documentation updated according to the comments * Logic in obtainVastUrl function updated according to the review comment. * Removed hook, enabled eslint
- Loading branch information
1 parent
4ac3582
commit 214efe8
Showing
3 changed files
with
289 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,89 @@ | ||
import { registerVideoSupport } from '../src/adServerManager'; | ||
import { targeting } from '../src/targeting'; | ||
import { format as buildUrl } from '../src/url'; | ||
import * as utils from '../src/utils'; | ||
import { config } from '../src/config'; | ||
|
||
const MODULE_NAME = 'Konduit'; | ||
|
||
function addLogLabel(args) { | ||
args = [].slice.call(args); | ||
args.unshift(`${MODULE_NAME}: `); | ||
return args; | ||
} | ||
|
||
export function logInfo() { | ||
utils.logInfo(...addLogLabel(arguments)); | ||
} | ||
|
||
export function logError() { | ||
utils.logError(...addLogLabel(arguments)); | ||
} | ||
|
||
export function buildVastUrl(options) { | ||
if (!options.params || !options.params.konduit_id) { | ||
logError(`'konduit_id' parameter is required for $$PREBID_GLOBAL$$.adServers.konduit.buildVastUrl function`); | ||
|
||
return null; | ||
} | ||
|
||
const bid = options.bid || targeting.getWinningBids()[0]; | ||
|
||
if (!bid) { | ||
logError('Bid is not provided or not found'); | ||
|
||
return null; | ||
} | ||
|
||
logInfo('The following bid will be wrapped: ', bid); | ||
|
||
const queryParams = {}; | ||
|
||
const vastUrl = obtainVastUrl(bid); | ||
|
||
if (vastUrl) { | ||
queryParams.konduit_id = options.params.konduit_id; | ||
queryParams.konduit_header_bidding = 1; | ||
queryParams.konduit_url = vastUrl; | ||
} else { | ||
logError('No VAST url found in the bid'); | ||
} | ||
|
||
let resultingUrl = null; | ||
|
||
if (queryParams.konduit_url) { | ||
resultingUrl = buildUrl({ | ||
protocol: 'https', | ||
host: 'p.konduit.me', | ||
pathname: '/api/vastProxy', | ||
search: queryParams | ||
}); | ||
|
||
logInfo(`Konduit wrapped VAST url: ${resultingUrl}`); | ||
} | ||
|
||
return resultingUrl; | ||
} | ||
|
||
function obtainVastUrl(bid) { | ||
const vastUrl = bid && bid.vastUrl; | ||
|
||
if (vastUrl) { | ||
logInfo(`VAST url found in the bid - ${vastUrl}`); | ||
|
||
return encodeURIComponent(vastUrl); | ||
} | ||
|
||
const cacheUrl = config.getConfig('cache.url'); | ||
if (cacheUrl) { | ||
const composedCacheUrl = `${cacheUrl}?uuid=${bid.videoCacheKey}`; | ||
|
||
logInfo(`VAST url is taken from cache.url: ${composedCacheUrl}`); | ||
|
||
return encodeURIComponent(composedCacheUrl); | ||
} | ||
} | ||
|
||
registerVideoSupport('konduit', { | ||
buildVastUrl: buildVastUrl, | ||
}); |
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,73 @@ | ||
## Konduit video tags wrapper | ||
|
||
Konduit Wrapper is a prebid module to generate Konduit wrapped VAST tag URLs for a provided bid or a winning bid. | ||
|
||
|
||
### Setup | ||
|
||
``` | ||
var videoAdUnit = [{ | ||
code: 'videoAd', | ||
mediaTypes: { | ||
video: { | ||
playerSize: [640, 480], | ||
context: 'instream' | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'appnexus', | ||
params: { | ||
placementId: 13232361, | ||
video: { | ||
skippable: true, | ||
playback_method: ['auto_play_sound_off'] | ||
} | ||
} | ||
}] | ||
}]; | ||
pbjs.que.push(function(){ | ||
pbjs.addAdUnits(videoAdUnit); | ||
pbjs.requestBids({ | ||
timeout : 700, | ||
bidsBackHandler : function(bids) { | ||
var winnerBid = pbjs.getHighestCpmBids('videoAd')[0]; | ||
var vastTagUrl = pbjs.adServers.konduit.buildVastUrl({ | ||
bid: winnerBid, // just in case if you want to pass your bid | ||
params: { | ||
konduit_id: 'your_konduit_id' | ||
} | ||
}); | ||
invokeVideoPlayer(vastTagUrl); | ||
} | ||
}); | ||
}); | ||
function invokeVideoPlayer(vastTagUrl) { | ||
videojs("video_player_id").ready(function() { | ||
this.vastClient({ | ||
adTagUrl: vastTagUrl, | ||
playAdAlways: true, | ||
verbosity: 4, | ||
autoplay: true | ||
}); | ||
this.play(); | ||
}); | ||
} | ||
``` | ||
|
||
Function parameters: | ||
* `bid` - prebid object with VAST url that should be wrapped (if not passed first winning bid from `auctionManager.getWinningBids()` is used) | ||
* `konduit_id` - your personal unique Konduit identifier (required) | ||
|
||
The function returns a Konduit wrapped VAST url if valid parameters are passed in. If some of the parameters are not passed or are invalid the function returns 'null' along with related error logs providing more details. | ||
|
||
|
||
### Building Prebid with the Konduit wrapper function | ||
|
||
Your Prebid build must include the **konduitWrapper** module. Follow the build instructions for Prebid as explained in the top level README.md file of the Prebid source tree. | ||
|
||
ex: $ gulp build --modules=konduitWrapper | ||
|
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,127 @@ | ||
import { expect } from 'chai'; | ||
|
||
import parse from 'url-parse'; | ||
import { buildVastUrl } from 'modules/konduitWrapper'; | ||
import { parseQS } from 'src/url'; | ||
import { config } from 'src/config'; | ||
|
||
describe('The Konduit vast wrapper module', function () { | ||
it('should make a wrapped request url when `bid` passed', function () { | ||
const bid = createBid(10, 'video1', 15, '10.00_15s', '123', '395'); | ||
|
||
const url = parse(buildVastUrl({ | ||
bid, | ||
params: { 'konduit_id': 'testId' }, | ||
})); | ||
|
||
expect(url.protocol).to.equal('https:'); | ||
expect(url.host).to.equal('p.konduit.me'); | ||
|
||
const queryParams = parseQS(url.query); | ||
expect(queryParams).to.have.property('konduit_url', encodeURIComponent('http://some-vast-url.com')); | ||
expect(queryParams).to.have.property('konduit_header_bidding', '1'); | ||
expect(queryParams).to.have.property('konduit_id', 'testId'); | ||
}); | ||
|
||
it('should return null when no `konduit_id` (required param) passed', function () { | ||
const bid = createBid(10, 'video1', 15, '10.00_15s', '123', '395'); | ||
|
||
const url = buildVastUrl({ bid }); | ||
|
||
expect(url).to.equal(null); | ||
}); | ||
|
||
it('should return null when either bid or adUnit is not passed', function () { | ||
const url = buildVastUrl({ params: { 'konduit_id': 'testId' } }); | ||
|
||
expect(url).to.equal(null); | ||
}); | ||
|
||
it('should return null when bid does not contain vastUrl', function () { | ||
const bid = createBid(10, 'video1', 15, '10.00_15s', '123', '395'); | ||
|
||
delete bid.vastUrl; | ||
|
||
const url = buildVastUrl({ | ||
bid, | ||
params: { 'konduit_id': 'testId' }, | ||
}); | ||
|
||
expect(url).to.equal(null); | ||
}); | ||
|
||
it('should return wrapped vastUrl based on cached url in params', function () { | ||
config.setConfig({ cache: { url: 'https://cached.url.com' } }); | ||
const bid = createBid(10, 'video1', 15, '10.00_15s', '123', '395'); | ||
|
||
delete bid.vastUrl; | ||
|
||
const expectedUrl = encodeURIComponent(`https://cached.url.com?uuid=${bid.videoCacheKey}`); | ||
|
||
const url = parse(buildVastUrl({ | ||
bid, | ||
params: { 'konduit_id': 'testId' }, | ||
})); | ||
const queryParams = parseQS(url.query); | ||
|
||
expect(queryParams).to.have.property('konduit_url', expectedUrl); | ||
|
||
config.resetConfig(); | ||
}); | ||
}); | ||
|
||
function createBid(cpm, adUnitCode, durationBucket, priceIndustryDuration, uuid, label) { | ||
return { | ||
'bidderCode': 'appnexus', | ||
'width': 640, | ||
'height': 360, | ||
'statusMessage': 'Bid available', | ||
'adId': '28f24ced14586c', | ||
'mediaType': 'video', | ||
'source': 'client', | ||
'requestId': '28f24ced14586c', | ||
'cpm': cpm, | ||
'creativeId': 97517771, | ||
'currency': 'USD', | ||
'netRevenue': true, | ||
'ttl': 3600, | ||
'adUnitCode': adUnitCode, | ||
'video': { | ||
'context': 'adpod', | ||
'durationBucket': durationBucket | ||
}, | ||
'appnexus': { | ||
'buyerMemberId': 9325 | ||
}, | ||
'vastUrl': 'http://some-vast-url.com', | ||
'vastImpUrl': 'http://some-vast-imp-url.com', | ||
'auctionId': 'ec266b31-d652-49c5-8295-e83fafe5532b', | ||
'responseTimestamp': 1548442460888, | ||
'requestTimestamp': 1548442460827, | ||
'bidder': 'appnexus', | ||
'timeToRespond': 61, | ||
'pbLg': '5.00', | ||
'pbMg': '5.00', | ||
'pbHg': '5.00', | ||
'pbAg': '5.00', | ||
'pbDg': '5.00', | ||
'pbCg': '', | ||
'size': '640x360', | ||
'adserverTargeting': { | ||
'hb_bidder': 'appnexus', | ||
'hb_adid': '28f24ced14586c', | ||
'hb_pb': '5.00', | ||
'hb_size': '640x360', | ||
'hb_source': 'client', | ||
'hb_format': 'video', | ||
'hb_pb_cat_dur': priceIndustryDuration, | ||
'hb_cache_id': uuid | ||
}, | ||
'customCacheKey': `${priceIndustryDuration}_${uuid}`, | ||
'meta': { | ||
'iabSubCatId': 'iab-1', | ||
'adServerCatId': label | ||
}, | ||
'videoCacheKey': '4cf395af-8fee-4960-af0e-88d44e399f14' | ||
} | ||
} |