-
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
Added myTarget Adapter #3599
Merged
Merged
Added myTarget Adapter #3599
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,108 @@ | ||
import * as utils from '../src/utils'; | ||
import * as url from '../src/url'; | ||
import { config } from '../src/config'; | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'mytarget'; | ||
const BIDDER_URL = '//ad.mail.ru/hbid_prebid/'; | ||
const DEFAULT_CURRENCY = 'RUB'; | ||
const DEFAULT_TTL = 180; | ||
|
||
function buildPlacement(bidRequest) { | ||
let { bidId, params } = bidRequest; | ||
let { placementId, position, response, bidfloor } = params; | ||
let placement = { | ||
placementId, | ||
id: bidId, | ||
position: position || 0, | ||
response: response || 0 | ||
}; | ||
|
||
if (typeof bidfloor !== 'undefined') { | ||
placement.bidfloor = bidfloor; | ||
} | ||
|
||
return placement; | ||
} | ||
|
||
function getSiteName(referrer) { | ||
let sitename = config.getConfig('mytarget.sitename'); | ||
|
||
if (!sitename) { | ||
sitename = url.parse(referrer).hostname; | ||
} | ||
|
||
return sitename; | ||
} | ||
|
||
function generateRandomId() { | ||
return Math.random().toString(16).substr(2); | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
|
||
isBidRequestValid: function(bid) { | ||
return !!bid.params.placementId; | ||
}, | ||
|
||
buildRequests: function(validBidRequests, bidderRequest) { | ||
let referrer = ''; | ||
|
||
if (bidderRequest && bidderRequest.refererInfo) { | ||
referrer = bidderRequest.refererInfo.referer; | ||
} | ||
|
||
const payload = { | ||
places: utils._map(validBidRequests, buildPlacement), | ||
site: { | ||
sitename: getSiteName(referrer), | ||
page: referrer | ||
}, | ||
settings: { | ||
currency: DEFAULT_CURRENCY, | ||
windowSize: { | ||
width: window.screen.width, | ||
height: window.screen.height | ||
} | ||
} | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: BIDDER_URL, | ||
data: payload, | ||
}; | ||
}, | ||
|
||
interpretResponse: function(serverResponse, bidRequest) { | ||
let { body } = serverResponse; | ||
|
||
if (body.bids) { | ||
return utils._map(body.bids, (bid) => { | ||
let bidResponse = { | ||
requestId: bid.id, | ||
cpm: bid.price, | ||
width: bid.size.width, | ||
height: bid.size.height, | ||
ttl: bid.ttl || DEFAULT_TTL, | ||
currency: bid.currency || DEFAULT_CURRENCY, | ||
creativeId: bid.creativeId || generateRandomId(), | ||
netRevenue: true | ||
} | ||
|
||
if (bid.adm) { | ||
bidResponse.ad = bid.adm; | ||
} else { | ||
bidResponse.adUrl = bid.displayUrl; | ||
} | ||
|
||
return bidResponse; | ||
}); | ||
} | ||
|
||
return []; | ||
} | ||
} | ||
|
||
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,40 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: myTarget Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: support_target@corp.my.com | ||
``` | ||
|
||
# Description | ||
|
||
Module that connects to myTarget demand sources. | ||
|
||
# Test Parameters | ||
|
||
``` | ||
var adUnits = [{ | ||
code: 'placementCode', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[240, 400]], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'mytarget', | ||
params: { | ||
placementId: '379783', | ||
|
||
// OPTIONAL: custom bid floor | ||
bidfloor: 10000, | ||
|
||
// OPTIONAL: if you know the ad position on the page, specify it here | ||
// (this corresponds to "Ad Position" in OpenRTB 2.3, section 5.4) | ||
position: 0, | ||
|
||
// OPTIONAL: bid response type: 0 - ad url (default), 1 - ad markup | ||
response: 0 | ||
} | ||
}] | ||
}]; | ||
``` |
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,199 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/mytargetBidAdapter'; | ||
|
||
describe('MyTarget Adapter', function() { | ||
describe('isBidRequestValid', function () { | ||
it('should return true when required params found', function () { | ||
let validBid = { | ||
bidder: 'mytarget', | ||
params: { | ||
placementId: '1' | ||
} | ||
}; | ||
|
||
expect(spec.isBidRequestValid(validBid)).to.equal(true); | ||
}); | ||
|
||
it('should return false for when required params are not passed', function () { | ||
let invalidBid = { | ||
bidder: 'mytarget', | ||
params: {} | ||
}; | ||
|
||
expect(spec.isBidRequestValid(invalidBid)).to.equal(false); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
let bidRequests = [ | ||
{ | ||
bidId: 'bid1', | ||
bidder: 'mytarget', | ||
params: { | ||
placementId: '1' | ||
} | ||
}, | ||
{ | ||
bidId: 'bid2', | ||
bidder: 'mytarget', | ||
params: { | ||
placementId: '2', | ||
position: 1, | ||
response: 1, | ||
bidfloor: 10000 | ||
} | ||
} | ||
]; | ||
let bidderRequest = { | ||
refererInfo: { | ||
referer: 'https://example.com?param=value' | ||
} | ||
}; | ||
|
||
let bidRequest = spec.buildRequests(bidRequests, bidderRequest); | ||
|
||
it('should build single POST request for multiple bids', function() { | ||
expect(bidRequest.method).to.equal('POST'); | ||
expect(bidRequest.url).to.equal('//ad.mail.ru/hbid_prebid/'); | ||
expect(bidRequest.data).to.be.an('object'); | ||
expect(bidRequest.data.places).to.be.an('array'); | ||
expect(bidRequest.data.places).to.have.lengthOf(2); | ||
}); | ||
|
||
it('should pass bid parameters', function() { | ||
let place1 = bidRequest.data.places[0]; | ||
let place2 = bidRequest.data.places[1]; | ||
|
||
expect(place1.placementId).to.equal('1'); | ||
expect(place2.placementId).to.equal('2'); | ||
expect(place1.id).to.equal('bid1'); | ||
expect(place2.id).to.equal('bid2'); | ||
}); | ||
|
||
it('should pass default position and response type', function() { | ||
let place = bidRequest.data.places[0]; | ||
|
||
expect(place.position).to.equal(0); | ||
expect(place.response).to.equal(0); | ||
}); | ||
|
||
it('should pass provided position and response type', function() { | ||
let place = bidRequest.data.places[1]; | ||
|
||
expect(place.position).to.equal(1); | ||
expect(place.response).to.equal(1); | ||
}); | ||
|
||
it('should not pass default bidfloor', function() { | ||
let place = bidRequest.data.places[0]; | ||
|
||
expect(place.bidfloor).not.to.exist; | ||
}); | ||
|
||
it('should not pass provided bidfloor', function() { | ||
let place = bidRequest.data.places[1]; | ||
|
||
expect(place.bidfloor).to.exist; | ||
expect(place.bidfloor).to.equal(10000); | ||
}); | ||
|
||
it('should pass site parameters', function() { | ||
let site = bidRequest.data.site; | ||
|
||
expect(site).to.be.an('object'); | ||
expect(site.sitename).to.equal('example.com'); | ||
expect(site.page).to.equal('https://example.com?param=value'); | ||
}); | ||
|
||
it('should pass settings', function() { | ||
let settings = bidRequest.data.settings; | ||
|
||
expect(settings).to.be.an('object'); | ||
expect(settings.currency).to.equal('RUB'); | ||
expect(settings.windowSize).to.be.an('object'); | ||
expect(settings.windowSize.width).to.equal(window.screen.width); | ||
expect(settings.windowSize.height).to.equal(window.screen.height); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', function () { | ||
let serverResponse = { | ||
body: { | ||
'bidder_status': | ||
[ | ||
{ | ||
'bidder': 'mail.ru', | ||
'response_time_ms': 100, | ||
'num_bids': 2 | ||
} | ||
], | ||
'bids': | ||
[ | ||
{ | ||
'displayUrl': 'https://ad.mail.ru/hbid_imp/12345', | ||
'size': | ||
{ | ||
'height': '400', | ||
'width': '240' | ||
}, | ||
'id': '1', | ||
'currency': 'RUB', | ||
'price': 100, | ||
'ttl': 360, | ||
'creativeId': '123456' | ||
}, | ||
{ | ||
'adm': '<p>Ad</p>', | ||
'size': | ||
{ | ||
'height': '250', | ||
'width': '300' | ||
}, | ||
'id': '2', | ||
'price': 200 | ||
} | ||
] | ||
} | ||
}; | ||
|
||
let bids = spec.interpretResponse(serverResponse); | ||
|
||
it('should return empty array for response with no bids', function() { | ||
let emptyBids = spec.interpretResponse({ body: {} }); | ||
|
||
expect(emptyBids).to.have.lengthOf(0); | ||
}); | ||
|
||
it('should parse all bids from response', function() { | ||
expect(bids).to.have.lengthOf(2); | ||
}); | ||
|
||
it('should parse bid with ad url', function() { | ||
expect(bids[0].requestId).to.equal('1'); | ||
expect(bids[0].cpm).to.equal(100); | ||
expect(bids[0].width).to.equal('240'); | ||
expect(bids[0].height).to.equal('400'); | ||
expect(bids[0].ttl).to.equal(360); | ||
expect(bids[0].currency).to.equal('RUB'); | ||
expect(bids[0]).to.have.property('creativeId'); | ||
expect(bids[0].creativeId).to.equal('123456'); | ||
expect(bids[0].netRevenue).to.equal(true); | ||
expect(bids[0].adUrl).to.equal('https://ad.mail.ru/hbid_imp/12345'); | ||
expect(bids[0]).to.not.have.property('ad'); | ||
}); | ||
|
||
it('should parse bid with ad markup', function() { | ||
expect(bids[1].requestId).to.equal('2'); | ||
expect(bids[1].cpm).to.equal(200); | ||
expect(bids[1].width).to.equal('300'); | ||
expect(bids[1].height).to.equal('250'); | ||
expect(bids[1].ttl).to.equal(180); | ||
expect(bids[1].currency).to.equal('RUB'); | ||
expect(bids[1]).to.have.property('creativeId'); | ||
expect(bids[1].creativeId).not.to.equal('123456'); | ||
expect(bids[1].netRevenue).to.equal(true); | ||
expect(bids[1].ad).to.equal('<p>Ad</p>'); | ||
expect(bids[1]).to.not.have.property('adUrl'); | ||
}); | ||
}); | ||
}); |
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.
substr
should be replaced withsubstring
, you can view reason here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substrThere 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.
@idettman, thank you!
I've committed the fixed version, but the tests on CircleCI failed.
https://circleci.com/gh/prebid/Prebid.js/1895
By the way, should the same replacement be applied to the core?
https://github.com/prebid/Prebid.js/blob/master/src/utils.js#L87