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

Include gdpr TripleLift #2663

Merged
merged 19 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
186 changes: 186 additions & 0 deletions integrationExamples/gpt/custom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this file. We already have a gdpr hello world example.

<head>
<!-- Prebid Config Section START -->
<!-- Make sure this is inserted before your GPT tag -->
<script>window.__cmp = {config: {logging: 'debug'}}</script>
<script src="//acdn.adnxs.com/cmp/cmp.complete.bundle.js" async></script>

<script>
var PREBID_TIMEOUT = 100000;

var adUnits = [{
code: 'div-gpt-ad-1522123315348-0',
mediaTypes: {
banner: {
sizes: [[300, 600], [300, 250], [320, 90]],
}
},
bids: [
{
bidder: 'triplelift',
params: {
inventoryCode: 'forbes_main',
floor: 0.000
}
},{
bidder: 'appnexus',
params: {
placementId: '10433394'
}
}]
}, {
code: 'div-gpt-ad-1525796922726-0',
mediaTypes: {
banner: {
sizes: [[300, 300]],
}
},
bids: [
{
bidder: 'triplelift',
params: {
inventoryCode: 'forbes_main',
floor: 0.00
}
},{
bidder: 'appnexus',
params: {
placementId: '10433394'
}
}]
}, {
code: 'div-gpt-ad-1525797221569-0',
mediaTypes: {
banner: {
sizes: [[300, 600], [300, 250]],
}
},
bids: [
{
bidder: 'triplelift',
params: {
inventoryCode: 'forbes_main',
floor: 0
}
},{
bidder: 'appnexus',
params: {
placementId: '10433394'
}
}]
}];
//
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];


// this throws an error becuase enableSendAllBids is not defined
// pbjs.que.push(function() {
// pbjs.setConfig({enableSendAllBids});
// });

</script>
<!-- Prebid Config Section END -->

<!-- Prebid Boilerplate Section START. No Need to Edit. -->
<script type="text/javascript" src="http://localhost:9999/build/dev/prebid.js" async></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
consentManagement: {
cmpApi: 'iab',
timeout: 5000,
allowAuctionWithoutConsent: true
},
});
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});


function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);

</script>
<!-- Prebid Boilerplate Section END -->

<script>
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script>
googletag.cmd.push(function() {
googletag.defineSlot('/22979003/brittany_wendy', [300, 600], 'div-gpt-ad-1526414433563-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/22979003/prebid_test', [[300, 600], [300, 250]], 'div-gpt-ad-1525796922726-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
<script>
googletag.cmd.push(function() {
googletag.defineSlot('/22979003/SafeframeTest', [300, 250], 'div-gpt-ad-1525797221569-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<h2>Prebid.js Test</h2>

<!-- /22979003/brittany_wendy -->
<div id='div-gpt-ad-1526414433563-0' style='height:600px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1526414433563-0'); });
</script>
</div>
<!-- /22979003/prebid_test -->
<div id='div-gpt-ad-1525796922726-0'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1525796922726-0'); });
</script>
</div>
<!-- /22979003/SafeframeTest -->
<div id='div-gpt-ad-1525797221569-0' style='height:250px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1525797221569-0'); });
</script>
</div>

</body>
</html>
146 changes: 146 additions & 0 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { BANNER } from 'src/mediaTypes';
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';

const BIDDER_CODE = 'triplelift';
const STR_ENDPOINT = document.location.protocol + '//tlx.3lift.com/header/auction?';
var applies = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer let over var

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better name here would be gdprApplies

var consent_string = null;

export const tripleliftAdapterSpec = {

code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
aliases: ['triplelift'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary to alias your own code.

isBidRequestValid: function(bid) {
if (bid.params.inventoryCode === 'undefined') {
return false;
} else {
return true;
}
},

buildRequests: function(bidRequests, bidderRequest) {
var tlCall = STR_ENDPOINT;
var referrer = utils.getTopWindowUrl();
var data = _buildPostBody(bidRequests);

tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid');
tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$');
tlCall = utils.tryAppendQueryString(tlCall, 'fe', _isFlashEnabled().toString());
tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer);

if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') {
applies = bidderRequest.gdprConsent.gdprApplies;
tlCall = utils.tryAppendQueryString(tlCall, 'gdpr', applies.toString());
}
if (bidderRequest.gdprConsent.consentString !== 'undefined') {
consent_string = bidderRequest.gdprConsent.consentString;
tlCall = utils.tryAppendQueryString(tlCall, 'cmp_cs', consent_string);
}
if (tlCall.lastIndexOf('&') === tlCall.length - 1) {
tlCall = tlCall.substring(0, tlCall.length - 1);
}
utils.logMessage('tlCall request built: ' + tlCall);

return {
method: 'POST',
url: tlCall,
data,
bidderRequest
};
},

interpretResponse: function(serverResponse, {bidderRequest}) {
var bidResponses = [];
var bids = serverResponse.body.bids || [];

if (bids.length > 0) {
for (let i = 0; i < bids.length; i++) {
bidResponses.push(_buildResponseObject(bidderRequest, bids[i]));
}
}
return bidResponses;
},

getUserSyncs: function(syncOptions) {
var ibCall = '//ib.3lift.com/sync?';
if (consent_string !== null) {
ibCall = utils.tryAppendQueryString(ibCall, 'gdpr', applies);
ibCall = utils.tryAppendQueryString(ibCall, 'cmp_cs', consent_string);
}

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: ibCall
}];
}
}
}

function _buildPostBody(bidRequests) {
var data = {imp: []};

for (let i = 0; i < bidRequests.length; i++) {
data.imp.push(
{
id: i,
tagid: bidRequests[i].params.inventoryCode,
floor: bidRequests[i].params.floor,
banner: {
format: _sizes(bidRequests[i].sizes),
},
}
)
}
return data;
}

function _sizes(sizeArray) {
var format = [];
for (let i = 0; i < sizeArray.length; i++) {
format.push({
w: sizeArray[i][0],
h: sizeArray[i][1]
});
}
return format;
}

function _buildResponseObject(bidderRequest, bid) {
var width = bid.width || 1;
var height = bid.height || 1;
var dealId = bid.deal_id || '';
var creativeId = bid.imp_id;

if (bid.cpm != 0 && bid.ad) {
const bidResponse = {
requestId: bidderRequest.bids[creativeId].bidId,
cpm: bid.cpm,
width: width,
height: height,
netRevenue: true,
ad: bid.ad,
creativeId: creativeId,
dealId: dealId,
currency: 'USD',
ttl: 33,
};
return bidResponse;
};
}

function _isFlashEnabled() {
var flash;
try {
flash = Boolean(new ActiveXObject('ShockwaveFlash.ShockwaveFlash'));
} catch (e) {
flash = navigator.mimeTypes &&
navigator.mimeTypes['application/x-shockwave-flash'] !== undefined &&
navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin ? 1 : 0
}
return flash ? 1 : 0;
}

registerBidder(tripleliftAdapterSpec);