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

Reviving and moving to prebid 3.0 of smartyAds bi adapter #4671

Merged
merged 10 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
107 changes: 107 additions & 0 deletions modules/smartyadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {registerBidder} from '../src/adapters/bidderFactory';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes';
import * as utils from '../src/utils';

const BIDDER_CODE = 'smartyads';
const AD_URL = 'https://ssp-nj.webtradehub.com/?c=o&m=multi';
const URL_SYNC = 'https://ssp-nj.webtradehub.com/?c=o&m=cookie';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
!bid.ttl || !bid.currency) {
return false;
}
switch (bid['mediaType']) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl);
case NATIVE:
return Boolean(bid.title && bid.image && bid.impressionTrackers);
default:
return false;
}
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO, NATIVE],

isBidRequestValid: (bid) => {
return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placementId));
},

buildRequests: (validBidRequests = [], bidderRequest) => {
let winTop = window;
let location;
try {
location = new URL(bidderRequest.refererInfo.referer)
winTop = window.top;
} catch (e) {
location = winTop.location;
utils.logMessage(e);
};
let placements = [];
let request = {
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'language': (navigator && navigator.language) ? navigator.language : '',
'secure': 1,
'host': location.host,
'page': location.pathname,
'placements': placements
};
request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])
if (bidderRequest) {
if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
}
const len = validBidRequests.length;

for (let i = 0; i < len; i++) {
let bid = validBidRequests[i];
let traff = bid.params.traffic || BANNER
placements.push({
placementId: bid.params.placementId,
bidId: bid.bidId,
sizes: (traff != NATIVE) ? (bid.mediaTypes[traff].sizes || bid.sizes) : [],
traffic: traff
});
if (bid.schain) {
placement.schain = bid.schain;
}
}
return {
method: 'POST',
url: AD_URL,
data: request
};
},

interpretResponse: (serverResponse) => {
let response = [];
serverResponse = serverResponse.body;
for (let i = 0; i < serverResponse.length; i++) {
let resItem = serverResponse[i];
if (isBidResponseValid(resItem)) {
delete resItem.mediaType;
response.push(resItem);
}
}
return response;
},

getUserSyncs: (syncOptions, serverResponses) => {
return [{
type: 'image',
url: URL_SYNC
}];
}

};

registerBidder(spec);
60 changes: 51 additions & 9 deletions modules/smartyadsBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,58 @@ Module that connects to SmartyAds' demand sources

# Test Parameters
```
var adUnits = [{
code: 'placementId_0',
sizes: [[300, 250]],
bids: [{
bidder: 'smartyads',
params: {
placementId: 0,
traffic: 'banner'
var adUnits = [
// Will return static native ad. Assets are stored through user UI for each placement separetly
{
code: 'placementId_0',
mediaTypes: {
native: {}
},
bids: [
{
bidder: 'smartyads',
params: {
placementId: 0,
traffic: 'native'
}
}
}]
]
},
// Will return static test banner
{
code: 'placementId_0',
mediaTypes: {
video: {
sizes: [[300, 250]],
}
},
bids: [
{
bidder: 'smartyads',
params: {
placementId: 0,
traffic: 'video'
}
}
]
},
// Will return test vast xml. All video params are stored under placement in publishers UI
{
code: 'placementId_0',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
bids: [
{
bidder: 'smartyads',
params: {
placementId: 0,
traffic: 'banner'
}
}
]
}
];
```
Loading