Skip to content
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

Add flash detection to TripleLift adapter #855

Merged
merged 3 commits into from
Jan 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions src/adapters/triplelift.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
var tlReq = params.bids;
var bidsCount = tlReq.length;

//set expected bids count for callback execution
//bidmanager.setExpectedBidsCount('triplelift',bidsCount);
// set expected bids count for callback execution
// bidmanager.setExpectedBidsCount('triplelift',bidsCount);

for (var i = 0; i < bidsCount; i++) {
var bidRequest = tlReq[i];
var callbackId = bidRequest.bidId;
adloader.loadScript(buildTLCall(bidRequest, callbackId));
//store a reference to the bidRequest from the callback id
//bidmanager.pbCallbackMap[callbackId] = bidRequest;
// store a reference to the bidRequest from the callback id
// bidmanager.pbCallbackMap[callbackId] = bidRequest;
}

}


Expand All @@ -33,8 +32,7 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
var inventoryCode = utils.getBidIdParameter('inventoryCode', bid.params);
var floor = utils.getBidIdParameter('floor', bid.params);


//build our base tag, based on if we are http or https
// build our base tag, based on if we are http or https
var tlURI = '//tlx.3lift.com/header/auction?';
var tlCall = document.location.protocol + tlURI;

Expand All @@ -45,17 +43,20 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
tlCall = utils.tryAppendQueryString(tlCall, 'inv_code', inventoryCode);
tlCall = utils.tryAppendQueryString(tlCall, 'floor', floor);

//sizes takes a bit more logic
// indicate whether flash support exists
tlCall = utils.tryAppendQueryString(tlCall, 'fe', isFlashEnabled());

// sizes takes a bit more logic
var sizeQueryString = utils.parseSizesInput(bid.sizes);
if (sizeQueryString) {
tlCall += 'size=' + sizeQueryString + '&';
}

//append referrer
// append referrer
var referrer = utils.getTopWindowUrl();
tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer);

//remove the trailing "&"
// remove the trailing "&"
if (tlCall.lastIndexOf('&') === tlCall.length - 1) {
tlCall = tlCall.substring(0, tlCall.length - 1);
}
Expand All @@ -64,22 +65,36 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
utils.logMessage('tlCall request built: ' + tlCall);
// @endif

//append a timer here to track latency
// append a timer here to track latency
bid.startTime = new Date().getTime();

return tlCall;

}

function isFlashEnabled() {
var hasFlash = 0;
try {
// check for Flash support in IE
var fo = new window.ActiveXObject('ShockwaveFlash.ShockwaveFlash');
if (fo) { hasFlash = 1; }
} catch (e) {
if (navigator.mimeTypes &&
navigator.mimeTypes['application/x-shockwave-flash'] !== undefined &&
navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin) {
hasFlash = 1;
}
}
return hasFlash;
}

//expose the callback to the global object:
// expose the callback to the global object:
$$PREBID_GLOBAL$$.TLCB = function(tlResponseObj) {
if (tlResponseObj && tlResponseObj.callback_id) {
var bidObj = utils.getBidRequest(tlResponseObj.callback_id);
var placementCode = bidObj && bidObj.placementCode;

// @if NODE_ENV='debug'
if (bidObj) {utils.logMessage('JSONP callback function called for inventory code: ' + bidObj.params.inventoryCode);}
if (bidObj) { utils.logMessage('JSONP callback function called for inventory code: ' + bidObj.params.inventoryCode); }
// @endif

var bid = [];
Expand All @@ -95,7 +110,7 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
bidmanager.addBidResponse(placementCode, bid);

} else {
//no response data
// no response data
// @if NODE_ENV='debug'
if (bidObj) {utils.logMessage('No prebid response from TripleLift for inventory code: ' + bidObj.params.inventoryCode);}
// @endif
Expand All @@ -105,7 +120,7 @@ var TripleLiftAdapter = function TripleLiftAdapter() {
}

} else {
//no response data
// no response data
// @if NODE_ENV='debug'
utils.logMessage('No prebid response for placement %%PLACEMENT%%');
// @endif
Expand Down