Skip to content

Commit

Permalink
Adding support of Instream/Outstream Video for the SmileWanted Adapter (
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxSmileWanted authored and sa1omon committed Nov 28, 2019
1 parent afe1835 commit 28cc013
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 59 deletions.
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

0 comments on commit 28cc013

Please sign in to comment.