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

Added support of supply chain object for smartadserverBidAdapter #4975

Merged
merged 2 commits into from
Apr 2, 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
51 changes: 36 additions & 15 deletions modules/smartadserverBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,54 @@ export const spec = {
isBidRequestValid: function (bid) {
return !!(bid.params && bid.params.siteId && bid.params.pageId && bid.params.formatId);
},

/**
* Serialize a supply chain object to a string uri encoded
*
* @param {*} schain object
*/
serializeSupplyChain: function(schain) {
if (!schain || !schain.nodes) return null;
const nodesProperties = ['asi', 'sid', 'hp', 'rid', 'name', 'domain'];
return `${schain.ver},${schain.complete}!` +
schain.nodes.map(node => nodesProperties.map(prop =>
node[prop] ? encodeURIComponent(node[prop]) : '')
.join(','))
.join('!');
},

/**
* 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.
* @param {BidRequest[]} validBidRequests an array of bids
* @param {BidderRequest} 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 = {
let 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,
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$'
prebidVersion: '$prebid.version$',
schain: spec.serializeSupplyChain(bid.schain)
};

const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video');
Expand All @@ -66,7 +82,7 @@ export const spec = {
}));
} else if (videoMediaType && videoMediaType.context === 'instream') {
// Specific attributes for instream.
var playerSize = videoMediaType.playerSize[0];
let playerSize = videoMediaType.playerSize[0];
payload.isVideo = true;
payload.videoData = {
videoProtocol: bid.params.video.protocol,
Expand All @@ -88,27 +104,30 @@ export const spec = {
}

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.
* @param {*} bidRequestString
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function (serverResponse, bidRequestString) {
const bidResponses = [];
var response = serverResponse.body;
let response = serverResponse.body;
try {
if (response) {
const bidRequest = JSON.parse(bidRequestString.data);

var bidResponse = {
let bidResponse = {
requestId: bidRequest.bidId,
cpm: response.cpm,
width: response.width,
Expand Down Expand Up @@ -136,15 +155,16 @@ export const spec = {
}
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.
* @return {syncs[]} An array of syncs that should be executed.
*/
getUserSyncs: function (syncOptions, serverResponses) {
const syncs = []
const syncs = [];
if (syncOptions.iframeEnabled && serverResponses.length > 0) {
syncs.push({
type: 'iframe',
Expand All @@ -153,5 +173,6 @@ export const spec = {
}
return syncs;
}
}
};

registerBidder(spec);
47 changes: 46 additions & 1 deletion test/spec/modules/smartadserverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Smart bid adapter tests', function () {
transactionId: 'zsfgzzg'
}];

// Default params without optional ones
// Default params without optional ones
var DEFAULT_PARAMS_WO_OPTIONAL = [{
adUnitCode: 'sas_42',
bidId: 'abcd1234',
Expand Down Expand Up @@ -433,4 +433,49 @@ describe('Smart bid adapter tests', function () {
expect(request[1]).to.not.be.empty;
});
});

describe('Supply Chain Serializer tests', function () {
it('Verify a multi node supply chain serialization matches iab example', function() {
let schain = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.com',
'sid': '1234',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher',
'domain': 'publisher.com'
},
{
'asi': 'exchange2.com',
'sid': 'abcd',
'hp': 1,
'rid': 'bid-request-2',
'name': 'intermediary',
'domain': 'intermediary.com'
}
]
};

let serializedSchain = spec.serializeSupplyChain(schain);
expect(serializedSchain).to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com');
});

it('Verifiy that null schain produce null result', function () {
let actual = spec.serializeSupplyChain(null);
expect(null, actual);
});

it('Verifiy that schain with null nodes produce null result', function () {
let schain = {
'ver': '1.0',
'complete': 1

};
let actual = spec.serializeSupplyChain(null);
expect(null, actual);
});
});
});