-
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.
Adding a new Trion Interactive Adapter and associated tests to prebid.
- Loading branch information
Mike Groh
committed
Mar 21, 2017
1 parent
3787eda
commit ba32f46
Showing
3 changed files
with
410 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 |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
"widespace", | ||
"admixer", | ||
"tapsense", | ||
"trion", | ||
{ | ||
"appnexus": { | ||
"alias": "brealtime" | ||
|
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,132 @@ | ||
import { getBidRequest } from '../utils.js'; | ||
|
||
var CONSTANTS = require('../constants.json'); | ||
var utils = require('../utils.js'); | ||
var adloader = require('../adloader.js'); | ||
var bidmanager = require('../bidmanager.js'); | ||
var bidfactory = require('../bidfactory.js'); | ||
var Adapter = require('./adapter.js'); | ||
|
||
const BID_REQUEST_BASE_URL = "https://in-appadvertising.com/api/bidRequest?"; | ||
const USER_SYNC_URL = "https://in-appadvertising.com/api/userSync.js"; | ||
|
||
var TrionAdapter; | ||
TrionAdapter = function TrionAdapter() { | ||
var baseAdapter = Adapter.createNew('trion'); | ||
var userTag = null; | ||
|
||
baseAdapter.callBids = function (params) { | ||
var bids = params.bids || []; | ||
|
||
if(!bids.length){ | ||
return; | ||
} | ||
|
||
if (!window.TRION_INT) { | ||
adloader.loadScript(USER_SYNC_URL, function () { | ||
userTag = window.TRION_INT || {}; | ||
if(!userTag.to){ | ||
getBids(bids); | ||
} | ||
else{ | ||
setTimeout(function () { | ||
getBids(bids); | ||
}, userTag.to); | ||
} | ||
}, true); | ||
} else { | ||
userTag = window.TRION_INT; | ||
getBids(bids); | ||
} | ||
}; | ||
|
||
function getBids(bids){ | ||
if(!userTag.int_t) { | ||
userTag.int_t = window.TR_INT_T || -1; | ||
} | ||
|
||
for (var i = 0; i < bids.length; i++) { | ||
var bidRequest = bids[i]; | ||
var bidId = bidRequest.bidId; | ||
adloader.loadScript(buildTrionUrl(bidRequest, bidId)); | ||
} | ||
} | ||
|
||
function buildTrionUrl(bid, bidId) { | ||
var pubId = utils.getBidIdParameter('pubId', bid.params); | ||
var sectionId = utils.getBidIdParameter('sectionId', bid.params); | ||
var re = utils.getBidIdParameter('re', bid.params); | ||
var url = window.location.href; | ||
var sizes = utils.parseSizesInput(bid.sizes).join(','); | ||
|
||
var trionUrl = BID_REQUEST_BASE_URL; | ||
|
||
trionUrl = utils.tryAppendQueryString(trionUrl, 'callback', 'pbjs.handleTrionCB'); | ||
trionUrl = utils.tryAppendQueryString(trionUrl, 'bidId', bidId); | ||
trionUrl = utils.tryAppendQueryString(trionUrl, 'pubId', pubId); | ||
trionUrl = utils.tryAppendQueryString(trionUrl, 'sectionId', sectionId); | ||
trionUrl = utils.tryAppendQueryString(trionUrl, 're', re); | ||
if (url) { | ||
trionUrl += 'url=' + url + '&'; | ||
} | ||
if (sizes) { | ||
trionUrl += 'sizes=' + sizes + '&'; | ||
} | ||
if(userTag) { | ||
trionUrl += 'tag=' + encodeURIComponent(JSON.stringify(userTag)) + '&'; | ||
} | ||
|
||
//remove the trailing "&" | ||
if (trionUrl.lastIndexOf('&') === trionUrl.length - 1) { | ||
trionUrl = trionUrl.substring(0, trionUrl.length - 1); | ||
} | ||
|
||
return trionUrl; | ||
} | ||
|
||
//expose the callback to the global object: | ||
$$PREBID_GLOBAL$$.handleTrionCB = function (trionResponseObj) { | ||
var bid; | ||
var bidObj = {}; | ||
var placementCode = ''; | ||
|
||
if (trionResponseObj && trionResponseObj.bidId) { | ||
var bidCode; | ||
var bidId = trionResponseObj.bidId; | ||
var result = trionResponseObj && trionResponseObj.result; | ||
|
||
bidObj = getBidRequest(bidId); | ||
if (bidObj) { | ||
bidCode = bidObj.bidder; | ||
placementCode = bidObj.placementCode; | ||
} | ||
|
||
if (result && result.cpm && result.placeBid && result.ad) { | ||
var cpm = parseInt(result.cpm, 10) / 100; | ||
bid = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidObj); | ||
bid.bidderCode = bidCode; | ||
bid.cpm = cpm; | ||
bid.ad = result.ad; | ||
bid.width = result.width; | ||
bid.height = result.height; | ||
} | ||
} | ||
if(!bid) { | ||
bid = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidObj); | ||
} | ||
bidmanager.addBidResponse(placementCode, bid); | ||
}; | ||
|
||
return { | ||
callBids: baseAdapter.callBids, | ||
setBidderCode: baseAdapter.setBidderCode, | ||
createNew: TrionAdapter.createNew, | ||
buildTrionUrl: buildTrionUrl | ||
}; | ||
}; | ||
|
||
TrionAdapter.createNew = function () { | ||
return new TrionAdapter(); | ||
}; | ||
|
||
module.exports = TrionAdapter; |
Oops, something went wrong.