-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Smartico Bid Adapter: add new bid adapter #6486
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
02aeae0
Adding smartico adapter
65a324c
bug #6486 fix, added maintainer email
d36685c
bug #6486 fix, modified test parameters
6587e67
bug #6486 fix, modified test parameters #2
b3d342b
#6486 applied review related updates & fixes
93f0979
#6486 applied review related updates & fixes #2
ec597fc
#6486 applied review related updates & fixes #3
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import find from 'core-js-pure/features/array/find.js'; | ||
|
||
const SMARTICO_CONFIG = { | ||
bidRequestUrl: 'https://trmads.eu/preBidRequest', | ||
widgetUrl: 'https://trmads.eu/get', | ||
method: 'POST' | ||
} | ||
|
||
const BIDDER_CODE = 'smartico'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
isBidRequestValid: function (bid) { | ||
return !!(bid && bid.params && bid.params.token && bid.params.placementId); | ||
}, | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
var i | ||
var j | ||
var bid | ||
var bidParam | ||
var bidParams = [] | ||
var sizes | ||
var frameWidth = Math.round(window.screen.width) | ||
var frameHeight = Math.round(window.screen.height) | ||
for (i = 0; i < validBidRequests.length; i++) { | ||
bid = validBidRequests[i] | ||
if (bid.sizes) { | ||
sizes = bid.sizes | ||
} else if (typeof (BANNER) != 'undefined' && bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { | ||
sizes = bid.mediaTypes[BANNER].sizes | ||
} else if (frameWidth && frameHeight) { | ||
sizes = [[frameWidth, frameHeight]] | ||
} else { | ||
sizes = [] | ||
} | ||
for (j = 0; j < sizes.length; j++) { | ||
bidParam = { | ||
token: bid.params.token || '', | ||
bidId: bid.bidId, | ||
'banner-format-width': sizes[j][0], | ||
'banner-format-height': sizes[j][1] | ||
} | ||
if (bid.params.bannerFormat) { | ||
bidParam['banner-format'] = bid.params.bannerFormat | ||
} | ||
if (bid.params.language) { | ||
bidParam.language = bid.params.language | ||
} | ||
if (bid.params.region) { | ||
bidParam.region = bid.params.region | ||
} | ||
if (bid.params.regions && (bid.params.regions instanceof String || (bid.params.regions instanceof Array && bid.params.regions.length))) { | ||
bidParam.regions = bid.params.regions | ||
if (bidParam.regions instanceof Array) { | ||
bidParam.regions = bidParam.regions.join(',') | ||
} | ||
} | ||
bidParams.push(bidParam) | ||
} | ||
} | ||
|
||
var ServerRequestObjects = { | ||
method: SMARTICO_CONFIG.method, | ||
url: SMARTICO_CONFIG.bidRequestUrl, | ||
bids: validBidRequests, | ||
data: {bidParams: bidParams, auctionId: bidderRequest.auctionId} | ||
} | ||
|
||
return ServerRequestObjects; | ||
}, | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
var i | ||
var bid | ||
var bidObject | ||
var url | ||
var html | ||
var ad | ||
var token | ||
var language | ||
var scriptId | ||
var bidResponses = [] | ||
|
||
for (i = 0; i < serverResponse.length; i++) { | ||
ad = serverResponse[i]; | ||
bid = find(bidRequest.bids, bid => bid.bidId === ad.bidId) | ||
if (bid) { | ||
token = bid.params.token || '' | ||
|
||
language = bid.params.language || SMARTICO_CONFIG.language || '' | ||
|
||
scriptId = encodeURIComponent('smartico-widget-' + bid.params.placementId + '-' + i) | ||
|
||
url = SMARTICO_CONFIG.widgetUrl + '?token=' + encodeURIComponent(token) + '&auction-id=' + encodeURIComponent(bid.auctionId) + '&from-auction-buffer=1&own_session=1&ad=' + encodeURIComponent(ad.id) + '&scriptid=' + scriptId + (ad.bannerFormatAlias ? '&banner-format=' + encodeURIComponent(ad.bannerFormatAlias) : '') + (language ? '&language=' + encodeURIComponent(language) : '') | ||
|
||
html = '<script id="' + scriptId + '" async defer type="text/javascript" src="' + url + '"><\/script>' | ||
|
||
bidObject = { | ||
requestId: bid.bidId, | ||
cpm: ad.cpm, | ||
width: parseInt(ad.bannerFormatWidth), | ||
height: parseInt(ad.bannerFormatHeight), | ||
creativeId: ad.id, | ||
netRevenue: false, // gross | ||
ttl: ad.ttl, | ||
ad: html | ||
} | ||
bidResponses.push(bidObject); | ||
} | ||
} | ||
return bidResponses; | ||
} | ||
} | ||
registerBidder(spec) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Overview | ||
|
||
Module Name: Smartico Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: sk@smartico.eu | ||
|
||
# Description | ||
|
||
Module that connects to Smartico's demand sources. | ||
|
||
# Test Parameters | ||
|
||
var adUnits = [ | ||
{ | ||
code: 'medium_rectangle', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250]], // a display size | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'smartico', | ||
params: { | ||
placementId: 'testPlacementId', | ||
token: "FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya" | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import {expect} from 'chai'; | ||
import {spec} from 'modules/smarticoBidAdapter.js'; | ||
import {newBidder} from 'src/adapters/bidderFactory.js'; | ||
|
||
describe('smarticoBidAdapter', function () { | ||
const adapter = newBidder(spec); | ||
let bid = { | ||
adUnitCode: 'adunit-code', | ||
auctionId: '5kaj89l8-3456-2s56-c455-4g6h78jsdfgf', | ||
bidRequestsCount: 1, | ||
bidder: 'smartico', | ||
bidderRequestId: '24081afs940568', | ||
bidderRequestsCount: 1, | ||
bidderWinsCount: 0, | ||
bidId: '22499d052045', | ||
mediaTypes: {banner: {sizes: [[300, 250]]}}, | ||
params: { | ||
token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', | ||
placementId: 'testPlacementId' | ||
}, | ||
sizes: [ | ||
[300, 250] | ||
], | ||
transactionId: '34562345-4dg7-46g7-4sg6-45gdsdj8fd56' | ||
} | ||
let bidderRequests = { | ||
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', | ||
auctionStart: 1579746300522, | ||
bidderCode: 'myBidderCode', | ||
bidderRequestId: '15246a574e859f', | ||
bids: [bid], | ||
refererInfo: { | ||
canonicalUrl: '', | ||
numIframes: 0, | ||
reachedTop: true | ||
} | ||
} | ||
describe('isBidRequestValid', function () { | ||
it('should return true where required params found', function () { | ||
expect(spec.isBidRequestValid(bid)).to.equal(true); | ||
}); | ||
}); | ||
describe('buildRequests', function () { | ||
let bidRequests = [ bid ]; | ||
let request = spec.buildRequests(bidRequests, bidderRequests); | ||
it('sends bid request via POST', function () { | ||
expect(request.method).to.equal('POST'); | ||
}); | ||
it('must contain token', function() { | ||
expect(request.data.bidParams[0].token).to.equal('FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya'); | ||
}); | ||
it('must contain auctionId', function() { | ||
expect(request.data.auctionId).to.exist.and.to.be.a('string') | ||
}); | ||
it('must contain valid width and height', function() { | ||
expect(request.data.bidParams[0]['banner-format-width']).to.exist.and.to.be.a('number') | ||
expect(request.data.bidParams[0]['banner-format-height']).to.exist.and.to.be.a('number') | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
let bidRequest = { | ||
method: 'POST', | ||
url: 'https://trmads.eu/preBidRequest', | ||
bids: [bid], | ||
data: [{ | ||
token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', | ||
bidId: '22499d052045', | ||
'banner-format-width': 300, | ||
'banner-format-height': 250, | ||
placementId: 'testPlacementId', | ||
}] | ||
}; | ||
let serverResponse = [{ | ||
bidId: '22499d052045', | ||
id: 987654, | ||
cpm: 10, | ||
ttl: 30, | ||
bannerFormatWidth: 300, | ||
bannerFormatHeight: 250, | ||
bannerFormatAlias: 'medium_rectangle' | ||
}]; | ||
let expectedResponse = [{ | ||
requestId: bid.bidId, | ||
cpm: 10, | ||
width: 300, | ||
height: 250, | ||
creativeId: 987654, | ||
netRevenue: false, // gross | ||
ttl: 30, | ||
ad: '<script id="smartico-widget-testPlacementId-0" async defer type="text/javascript" src="https://trmads.eu/get?token=FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya&auction-id=5kaj89l8-3456-2s56-c455-4g6h78jsdfgf&from-auction-buffer=1&own_session=1&ad=987654&scriptid=smartico-widget-testPlacementId-0&banner-format=medium_rectangle"><\/script>'}]; | ||
let result = spec.interpretResponse(serverResponse, bidRequest); | ||
it('should contain correct creativeId', function () { | ||
expect(result[0].creativeId).to.equal(expectedResponse[0].creativeId) | ||
}); | ||
it('should contain correct cpm', function () { | ||
expect(result[0].cpm).to.equal(expectedResponse[0].cpm) | ||
}); | ||
it('should contain correct width', function () { | ||
expect(result[0].width).to.equal(expectedResponse[0].width) | ||
}); | ||
it('should contain correct height', function () { | ||
expect(result[0].height).to.equal(expectedResponse[0].height) | ||
}); | ||
it('should contain correct requestId', function () { | ||
expect(result[0].requestId).to.equal(expectedResponse[0].requestId) | ||
}); | ||
it('should contain correct ttl', function () { | ||
expect(result[0].ttl).to.equal(expectedResponse[0].ttl) | ||
}); | ||
it('should contain correct netRevenue', function () { | ||
expect(result[0].netRevenue).to.equal(expectedResponse[0].netRevenue) | ||
}); | ||
it('should contain correct ad content', function () { | ||
expect(result[0].ad).to.equal(expectedResponse[0].ad) | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will not be sent, if you need it in your payload, you should move it into
data{}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'bids' are added in order to be available in the 'interpretResponse' function (as property of the second argument), no need to send them.