Skip to content

Commit

Permalink
Feature/smart video (#4367)
Browse files Browse the repository at this point in the history
* Adding outstream video support.

* Fixing unit test.

* Adding video instream support.

* Handling video startDelay parameter.

* Improving unit tests.

* Fixing indent.

* Handling the request when videoMediaType context is not supported.

* Changing maintainer mail address.

* Remove video outstream specific code.

* Unit test updated.
  • Loading branch information
tadam75 authored and jsnellbaker committed Nov 20, 2019
1 parent f1c7972 commit ed760f5
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 99 deletions.
52 changes: 42 additions & 10 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * as utils from '../src/utils';
import {
BANNER,
VIDEO
} from '../src/mediaTypes';
import {
config
} from '../src/config';
Expand All @@ -9,6 +13,7 @@ const BIDDER_CODE = 'smartadserver';
export const spec = {
code: BIDDER_CODE,
aliases: ['smart'], // short code
supportedMediaTypes: [BANNER, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand All @@ -33,6 +38,7 @@ export const spec = {

// pull requested transaction ID from bidderRequest.bids[].transactionId
return validBidRequests.map(bid => {
// Common bid request attributes for banner, outstream and instream.
var payload = {
siteid: bid.params.siteId,
pageid: bid.params.pageId,
Expand All @@ -44,17 +50,33 @@ export const spec = {
appname: bid.params.appName && bid.params.appName != '' ? bid.params.appName : undefined,
ckid: bid.params.ckId || 0,
tagId: bid.adUnitCode,
sizes: bid.sizes.map(size => ({
w: size[0],
h: size[1]
})),
pageDomain: utils.getTopWindowUrl(),
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
bidId: bid.bidId,
prebidVersion: '$prebid.version$'
};

const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
if (!videoMediaType) {
payload.sizes = bid.sizes.map(size => ({
w: size[0],
h: size[1]
}));
} else if (videoMediaType && videoMediaType.context === 'instream') {
// Specific attributes for instream.
var playerSize = videoMediaType.playerSize[0];
payload.isVideo = true;
payload.videoData = {
videoProtocol: bid.params.video.protocol,
playerWidth: playerSize[0],
playerHeight: playerSize[1],
adBreak: bid.params.video.startDelay || 0
};
} else {
return {};
}

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
Expand All @@ -74,13 +96,15 @@ export const spec = {
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequest) {
interpretResponse: function (serverResponse, bidRequestString) {
const bidResponses = [];
var response = serverResponse.body;
try {
if (response) {
const bidResponse = {
requestId: JSON.parse(bidRequest.data).bidId,
const bidRequest = JSON.parse(bidRequestString.data);

var bidResponse = {
requestId: bidRequest.bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
Expand All @@ -89,10 +113,18 @@ export const spec = {
currency: response.currency,
netRevenue: response.isNetCpm,
ttl: response.ttl,
referrer: utils.getTopWindowUrl(),
adUrl: response.adUrl,
ad: response.ad
referrer: utils.getTopWindowUrl()
};

if (bidRequest.isVideo) {
bidResponse.mediaType = VIDEO;
bidResponse.vastUrl = response.adUrl;
bidResponse.vastXml = response.ad;
} else {
bidResponse.adUrl = response.adUrl;
bidResponse.ad = response.ad;
}

bidResponses.push(bidResponse);
}
} catch (error) {
Expand Down
101 changes: 64 additions & 37 deletions modules/smartadserverBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: Smart Ad Server Bidder Adapter
Module Type: Bidder Adapter
Maintainer: gcarnec@smartadserver.com
Maintainer: support@smartadserver.com
```

# Description
Expand All @@ -18,45 +18,72 @@ Please reach out to your Technical account manager for more information.
## Web
```
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 62913,
ckId: 1122334455 // optional
}
}
]
}
];
{
code: 'test-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 62913,
ckId: 1122334455 // optional
}
}
]
}
];
```

## In-app
```
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 65906,
buId: "com.smartadserver.android.dashboard", // in-app only
appName: "Smart AdServer Preview", // in-app only
ckId: 1122334455 // optional
}
}
]
}
];
{
code: 'test-div',
sizes: [[300, 250]], // a display size
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 65906,
buId: "com.smartadserver.android.dashboard", // in-app only
appName: "Smart AdServer Preview", // in-app only
ckId: 1122334455 // optional
}
}
]
}
];
```

## Instream Video
```
var videoAdUnit = {
code: 'test-div',
mediaTypes: {
video: {
context: 'instream',
playerSize: [640, 480]
}
},
bids: [{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
siteId: 326147,
pageId: 1153895,
formatId: 55710
bidfloor: 5,
video: {
protocol: 6,
startDelay: 0
}
}
}]
};
```
Loading

0 comments on commit ed760f5

Please sign in to comment.