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

Updating smartadserver adapter for prebid v3 compatibility. #4714

Merged
merged 1 commit into from
Jan 21, 2020
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
153 changes: 153 additions & 0 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import * as utils from '../src/utils';
import {
BANNER,
VIDEO
} from '../src/mediaTypes';
import {
config
} from '../src/config';
import {
registerBidder
} from '../src/adapters/bidderFactory';
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.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.siteId && bid.params.pageId && bid.params.formatId);
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @param {bidderRequest} - bidder request object
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
// use bidderRequest.bids[] to get bidder-dependent request info

// if your bidder supports multiple currencies, use config.getConfig(currency)
// to find which one the ad server needs

// 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,
formatid: bid.params.formatId,
currencyCode: config.getConfig('currency.adServerCurrency'),
bidfloor: bid.params.bidfloor || 0.0,
targeting: bid.params.target && bid.params.target != '' ? bid.params.target : undefined,
buid: bid.params.buId && bid.params.buId != '' ? bid.params.buId : undefined,
appname: bid.params.appName && bid.params.appName != '' ? bid.params.appName : undefined,
ckid: bid.params.ckId || 0,
tagId: bid.adUnitCode,
pageDomain: bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer ? bidderRequest.refererInfo.referer : undefined,
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
bidId: bid.bidId,
prebidVersion: '$prebid.version$'
};

const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
if (!videoMediaType) {
const bannerMediaType = utils.deepAccess(bid, 'mediaTypes.banner');
payload.sizes = bannerMediaType.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
}

var payloadString = JSON.stringify(payload);
return {
method: 'POST',
url: (bid.params.domain !== undefined ? bid.params.domain : 'https://prg.smartadserver.com') + '/prebid/v1',
data: payloadString,
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequestString) {
const bidResponses = [];
var response = serverResponse.body;
try {
if (response) {
const bidRequest = JSON.parse(bidRequestString.data);

var bidResponse = {
requestId: bidRequest.bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creativeId,
dealId: response.dealId,
currency: response.currency,
netRevenue: response.isNetCpm,
ttl: response.ttl
};

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) {
utils.logError('Error while parsing smart server response', error);
}
return bidResponses;
},
/**
* User syncs.
*
* @param {*} syncOptions Publisher prebid configuration.
* @param {*} serverResponses A successful response from the server.
* @return {Syncs[]} An array of syncs that should be executed.
*/
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = []
if (syncOptions.iframeEnabled && serverResponses.length > 0) {
syncs.push({
type: 'iframe',
url: serverResponses[0].body.cSyncUrl
});
}
return syncs;
}
}
registerBidder(spec);
18 changes: 13 additions & 5 deletions modules/smartadserverBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ Please reach out to your Technical account manager for more information.
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]], // a display size
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
domain: 'https://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 62913,
Expand All @@ -42,12 +46,16 @@ Please reach out to your Technical account manager for more information.
var adUnits = [
{
code: 'test-div',
sizes: [[300, 250]], // a display size
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
domain: 'https://ww251.smartadserver.com',
siteId: 207435,
pageId: 896536,
formatId: 65906,
Expand All @@ -74,7 +82,7 @@ Please reach out to your Technical account manager for more information.
bids: [{
bidder: "smart",
params: {
domain: 'http://ww251.smartadserver.com',
domain: 'https://ww251.smartadserver.com',
siteId: 326147,
pageId: 1153895,
formatId: 55710
Expand Down
Loading