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

Adding support of Instream/Outstream Video for the SmileWanted Adapter #4064

Merged
merged 1 commit into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
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
53 changes: 50 additions & 3 deletions modules/smilewantedBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import * as utils from '../src/utils';
import { Renderer } from '../src/Renderer';
import { config } from '../src/config';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

export const spec = {
code: 'smilewanted',
aliases: ['smile', 'sw'],

supportedMediaTypes: [BANNER, VIDEO],
/**
* Determines whether or not the given bid request is valid.
*
Expand Down Expand Up @@ -65,6 +67,7 @@ export const spec = {
interpretResponse: function(serverResponse, bidRequest) {
const bidResponses = [];
var response = serverResponse.body;

try {
if (response) {
const bidResponse = {
Expand All @@ -77,10 +80,19 @@ export const spec = {
currency: response.currency,
netRevenue: response.isNetCpm,
ttl: response.ttl,
adUrl: response.adUrl,
ad: response.ad
ad: response.ad,
};

if (response.formatTypeSw == 'video_instream' || response.formatTypeSw == 'video_outstream') {
bidResponse['mediaType'] = 'video';
bidResponse['vastUrl'] = response.ad;
bidResponse['ad'] = null;
}

if (response.formatTypeSw == 'video_outstream') {
bidResponse['renderer'] = newRenderer(JSON.parse(bidRequest.data), response);
}

bidResponses.push(bidResponse);
}
} catch (error) {
Expand Down Expand Up @@ -110,4 +122,39 @@ export const spec = {
}
}

/**
* Create SmileWanted renderer
* @param requestId
* @returns {*}
*/
function newRenderer(bidRequest, bidResponse) {
const renderer = Renderer.install({
id: bidRequest.bidId,
url: bidResponse.OustreamTemplateUrl,
loaded: false
});

try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on newRenderer', err);
}
return renderer;
}

/**
* Initialise SmileWanted outstream
* @param bid
*/
function outstreamRender(bid) {
bid.renderer.push(() => {
window.SmileWantedOutStreamInit({
width: bid.width,
height: bid.height,
vastUrl: bid.vastUrl,
elId: bid.adUnitCode
});
});
}

registerBidder(spec);
40 changes: 40 additions & 0 deletions modules/smilewantedBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ To use us as a bidder you must have an account and an active "zoneId" on our Smi
# Test Parameters

## Web

### Display
```
var adUnits = [
{
Expand All @@ -28,4 +30,42 @@ To use us as a bidder you must have an account and an active "zoneId" on our Smi
]
}
];
```

### Video Instream
```
var videoAdUnit = {
code: 'video1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream'
}
},
bids: [{
bidder: 'smilewanted',
params: {
zoneId: 2,
}
}]
};
```

### Video Outstream
```
var videoAdUnit = {
code: 'video1',
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'outstream'
}
},
bids: [{
bidder: 'smilewanted',
params: {
zoneId: 3,
}
}]
};
```
Loading