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

Lifestreet adapter 3.0 #4927

Merged
merged 8 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
118 changes: 59 additions & 59 deletions integrationExamples/gpt/pbjs_video_adUnit.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,72 @@
<script src="/build/dev/prebid.js" async=true></script>
<script>

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
var pbjs = pbjs || {};
probably-kira marked this conversation as resolved.
Show resolved Hide resolved
pbjs.que = pbjs.que || [];

/*
adUnits can support video demand requests by setting 'mediaType' to
'video'. When an adUnit is configured to support video, all bidders
within that adUnit must be video-enabled as well, as configured in
adapters.json.
*/
var videoAdUnit = {
code: 'video1',
sizes: [640,480],
mediaTypes: { video: {} },
bids: [
{
bidder: 'appnexusAst',
params: {
placementId: '123456',
video: {
id: 123,
skipppable: true,
playback_method: ['auto_play_sound_off']
}
}
}
]
};
/*
adUnits can support video demand requests by setting 'mediaType' to
'video'. When an adUnit is configured to support video, all bidders
within that adUnit must be video-enabled as well, as configured in
adapters.json.
*/
var videoAdUnit = {
code: 'video1',
sizes: [640,480],
mediaTypes: { video: {} },
bids: [
{
bidder: 'appnexusAst',
params: {
placementId: '123456',
video: {
id: 123,
skipppable: true,
playback_method: ['auto_play_sound_off']
}
}
}
]
};

pbjs.que.push(function(){
pbjs.addAdUnits(videoAdUnit);
pbjs.requestBids({
timeout : 3000,
bidsBackHandler : function(bids) {
var adserverTag = '<dfp_tag>'; // base ad server tag, see: https://support.google.com/dfp_premium/answer/1068325
var options = {
'adserver': 'dfp',
'code': 'video1' //code that matches the video adUnit declared above
};
//generate URL
var masterTagUrl = pbjs.buildMasterVideoTagFromAdserverTag(adserverTag, options);
//send masterTagUrl to the video player
invokeVideoPlayer(masterTagUrl);
pbjs.que.push(function(){
pbjs.addAdUnits(videoAdUnit);
pbjs.requestBids({
timeout : 3000,
bidsBackHandler : function(bids) {
var adserverTag = '<dfp_tag>'; // base ad server tag, see: https://support.google.com/dfp_premium/answer/1068325
var options = {
'adserver': 'dfp',
'code': 'video1' //code that matches the video adUnit declared above
};
//generate URL
var masterTagUrl = pbjs.buildMasterVideoTagFromAdserverTag(adserverTag, options);
//send masterTagUrl to the video player
invokeVideoPlayer(masterTagUrl);

}
});
});
}
});
});


</script>
</head>
<body>

<div class="example-video-container">
<video id="vid1" class="video-js vjs-default-skin" autoplay controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='640'
height='480'
>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
<div class="example-video-container">
<video id="vid1" class="video-js vjs-default-skin" autoplay controls preload="auto"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{}'
width='640'
height='480'
>
<source src="http://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>

<p>Video Playback Not Supported</p>
</video>
</div>
<p>Video Playback Not Supported</p>
</video>
</div>

<script>
<script>

var vid1 = videojs('vid1');
vid1.muted(true);
Expand All @@ -99,11 +99,11 @@
This function called after prebid is back
*/
function invokeVideoPlayer(url) {
vid1.vast({
url: url
});
vid1.vast({
url: url
});
}
</script>
</script>

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

const BIDDER_CODE = 'lifestreet';
const ADAPTER_VERSION = 'prebidJS-3.0';
probably-kira marked this conversation as resolved.
Show resolved Hide resolved

const urlTemplate = template`https://ads.lfstmedia.com/gate/${'adapter'}/${'slot'}?adkey=${'adkey'}&ad_size=${'ad_size'}&__location=${'location'}&__referrer=${'referrer'}&__wn=${'wn'}&__sf=${'sf'}&__fif=${'fif'}&__if=${'if'}&__stamp=${'stamp'}&__pp=1&__hb=1&_prebid_json=1&__gz=1&deferred_format=vast_2_0,vast_3_0&__hbver=${'hbver'}`;

/**
* A helper function for template to generate string from boolean
*/
function boolToString(value) {
return value ? '1' : '0';
}

/**
* A helper function for template
*/
function isInteger(value) {
probably-kira marked this conversation as resolved.
Show resolved Hide resolved
return typeof value === 'number' &&
isFinite(value) && Math.floor(value) === value;
}

/**
* A helper function to form URL from the template
*/
function template(strings, ...keys) {
return function(...values) {
let dict = values[values.length - 1] || {};
let result = [strings[0]];
keys.forEach(function(key, i) {
let value = isInteger(key) ? values[key] : dict[key];
result.push(value, strings[i + 1]);
});
return result.join('');
};
}

/**
* Creates a bid requests for a given bid.
*
* @param {BidRequest} bid The bid params to use for formatting a request
*/
function formatBidRequest(bid, bidderRequest = {}) {
const {params} = bid;
const {referer} = (bidderRequest.refererInfo || {});
let url = urlTemplate({
adapter: 'prebid',
slot: params.slot,
adkey: params.adkey,
ad_size: params.ad_size,
location: referer,
referrer: referer,
wn: boolToString(/fb_http/i.test(window.name)),
sf: boolToString(window['sfAPI'] || window['$sf']),
fif: boolToString(window['inDapIF'] === true),
if: boolToString(window !== window.top),
stamp: new Date().getTime(),
hbver: ADAPTER_VERSION
});

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.gdprApplies !== undefined) {
const gdpr = '&__gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? '1' : '0');
url += gdpr;
}
if (bidderRequest.gdprConsent.consentString !== undefined) {
url += `&__consent=${bidderRequest.gdprConsent.consentString}`;
}
}

// ccpa support
if (bidderRequest.uspConsent) {
url += `&__us_privacy=${bidderRequest.uspConsent}`
}

return {
method: 'GET',
url: url,
bidId: bid.bidId
};
}

function isResponseValid(response) {
console.log(response)
probably-kira marked this conversation as resolved.
Show resolved Hide resolved
return !/^\s*\{\s*"advertisementAvailable"\s*:\s*false/i.test(response.content) &&
response.content.indexOf('<VAST version="2.0"></VAST>') === -1 && (typeof response.cpm !== 'undefined') &&
response.status === 1;
}

export const spec = {
code: BIDDER_CODE,
aliases: ['lsm'],
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: (bid = {}) => {
const {params = {}} = bid
return !!(params.slot && params.adkey && params.ad_size);
},

buildRequests: (validBidRequests, bidderRequest) => {
return validBidRequests.map(bid => {
return formatBidRequest(bid, bidderRequest)
});
},
interpretResponse: (serverResponse, bidRequest) => {
const bidResponses = [];
let response = serverResponse.body;

if (!isResponseValid(response)) {
return bidResponses;
}

const bidResponse = {
requestId: bidRequest.bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creativeId,
currency: response.currency ? response.currency : 'USD',
netRevenue: response.netRevenue ? response.netRevenue : true,
ttl: response.ttl ? response.ttl : 86400
};

if (response.hasOwnProperty('dealId')) {
bidResponse.dealId = response.dealId;
}
if (response.content_type.indexOf('vast') > -1) {
if (typeof response.vastUrl !== 'undefined') {
bidResponse.vastUrl = response.vastUrl;
} else {
bidResponse.vastXml = response.content;
}

bidResponse.mediaType = VIDEO;
} else {
bidResponse.ad = response.content;
bidResponse.mediaType = BANNER;
}

bidResponses.push(bidResponse);
return bidResponses;
}
};

registerBidder(spec);
58 changes: 55 additions & 3 deletions modules/lifestreetBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# Overview

```
Module Name: Lifestreet Bid Adapter

Module Type: Lifestreet Adapter

Maintainer: [email protected]
```

# Description

Module that connects to Lifestreet's demand sources

Values, listed in `ALL_BANNER_SIZES` and `ALL_VIDEO_SIZES` are all the values which our server supports.
For `ad_size`, please use one of that values in following format: `ad_size: WIDTHxHEIGHT`

# Test Parameters
```javascript
var adUnits = [
const ALL_BANNER_SIZES = [
[120, 600], [160, 600], [300, 250], [300, 600], [320, 480],
[320, 50], [468, 60], [510, 510], [600, 300],
[720, 300], [728, 90], [760, 740], [768, 1024]
];

const ALL_VIDEO_SIZES = [
[640, 480], [650, 520], [970, 580]
]
const adUnits = [
// Banner adUnit
{
code: 'test-ad',
Expand Down Expand Up @@ -45,3 +57,43 @@ Module that connects to Lifestreet's demand sources
}
];
```

# Test Parameters (Banner)
```
const adUnits = [
{
code: 'test-ad',
sizes: [[160, 600]],
probably-kira marked this conversation as resolved.
Show resolved Hide resolved
bids: [
{
bidder: 'lifestreet',
params: {
slot: 'slot166704',
adkey: '78c',
ad_size: '160x600'
}
}
]
},
];
```

# Test Parameters (Video)
```
const adUnits = [
{
code: 'test-video-ad',
sizes: [[640, 480]],
bids: [
{
bidder: 'lifestreet',
params: {
slot: 'slot1227631',
adkey: 'a98',
ad_size: '640x480'
}
}
]
}
];
```
Loading