forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Dailymotion Bid Adapter : New bidder adapter #1
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38e19b0
.md, .js and _spec.js files added for dm bid adapter
Aditi0101 0d88f66
.md updated
Aditi0101 274a117
code name updated
Aditi0101 715a40c
feat(dailymotion-adaptor): refactor for submission
1b0ac5c
style(dailymotion-docs): code snippet indentation
0207876
style(dailymotion-docs): section spacing
9048935
docs(dailymotion-adaptor): const instead of var
f0730c5
fix(dailymotion-adaptor): remove irrelevant doc & verify validBidRequ…
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,56 @@ | ||
import { config } from '../src/config.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { VIDEO } from '../src/mediaTypes.js'; | ||
|
||
export const spec = { | ||
code: 'dailymotion', | ||
gvlid: 573, | ||
supportedMediaTypes: [VIDEO], | ||
|
||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* The only mandatory parameters for a bid to be valid are the api_key and position configuration entries. | ||
* Other parameters are optional. | ||
* | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: () => { | ||
const dmConfig = config.getConfig('dailymotion'); | ||
return !!(dmConfig?.api_key && dmConfig?.position); | ||
}, | ||
|
||
/** | ||
* Make a server request from the list of valid BidRequests (that already passed the isBidRequestValid call) | ||
* | ||
* @param {BidRequest[]} validBidRequests A non-empty list of valid bid requests that should be sent to the Server. | ||
* @param {BidderRequest} bidderRequest | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: (validBidRequests, bidderRequest) => (validBidRequests || []).map(bid => ({ | ||
method: 'POST', | ||
url: 'https://pb.dmxleo.com', | ||
data: { | ||
bidder_request: bidderRequest, | ||
config: config.getConfig('dailymotion'), | ||
coppa: config.getConfig('coppa'), | ||
request: bid, | ||
}, | ||
options: { | ||
withCredentials: true, | ||
crossOrigin: true | ||
}, | ||
})), | ||
|
||
/** | ||
* Map the response from the server into a list of bids. | ||
* As dailymotion prebid server returns an entry with the correct Prebid structure, | ||
* we directly include it as the only bid in the response. | ||
* | ||
* @param {*} serverResponse A successful response from the server. | ||
* @param {BidRequest} bidRequest | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: serverResponse => serverResponse?.body ? [serverResponse.body] : [], | ||
}; | ||
|
||
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,73 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Dailymotion Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: ad-leo-engineering@dailymotion.com | ||
``` | ||
|
||
# Description | ||
|
||
Dailymotion prebid adapter. | ||
|
||
# Configuration options | ||
|
||
Before calling this adapter, you need to set its configuration with a call to setConfig like this: | ||
|
||
``` | ||
config.setConfig({ | ||
dailymotion: { | ||
api_key: 'test_api_key', | ||
position: 'test_position', | ||
xid: 'x123456' | ||
} | ||
}); | ||
``` | ||
|
||
This call must be made before each auction. Here's a description of each parameter: | ||
* `api_key` is your publisher API key. For testing purpose, you can use "dailymotion-testing". | ||
* `position` parameter is the ad position in the video and must either be "preroll", "midroll" or "postroll". | ||
* `xid` is the video XID and should be provided to have better contextual data and higher fillrate | ||
|
||
# Test Parameters | ||
|
||
By setting the following configuration options, you'll get a constant response to any request to validate your adapter integration: | ||
|
||
``` | ||
config.setConfig({ | ||
dailymotion: { | ||
api_key: 'dailymotion-testing', | ||
position: 'preroll' | ||
} | ||
}); | ||
``` | ||
|
||
Please note that failing to set these configuration options will result in the adapter not bidding at all. | ||
|
||
# Sample video AdUnit | ||
|
||
``` | ||
const adUnits = [ | ||
{ | ||
code: 'test-ad-unit', | ||
mediaTypes: { | ||
video: { | ||
context: 'instream', | ||
playerSize: [640, 480], | ||
}, | ||
}, | ||
bids: [{ | ||
bidder: "dailymotion", | ||
params: {} | ||
}] | ||
} | ||
]; | ||
``` | ||
|
||
# Integrating the adapter | ||
|
||
To use the adapter with any non-test request, you first need to ask an API key from Dailymotion. Please contact on **ad-leo-engineering@dailymotion.com**. | ||
|
||
You will then be able to use it within the `config` before making a bid request. | ||
|
||
This API key will ensure proper identification of your inventory and allow you to get real bids. |
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,130 @@ | ||
import { config } from 'src/config.js'; | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/dailymotionBidAdapter.js'; | ||
|
||
describe('dailymotionBidAdapterTests', () => { | ||
// Validate that isBidRequestValid only validates requests | ||
// with both api_key and position config parameters set | ||
it('validates isBidRequestValid', () => { | ||
config.setConfig({ dailymotion: {} }); | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'dailymotion', | ||
})).to.be.false; | ||
|
||
config.setConfig({ dailymotion: { api_key: 'test_api_key' } }); | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'dailymotion', | ||
})).to.be.false; | ||
|
||
config.setConfig({ dailymotion: { position: 'test_position' } }); | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'dailymotion', | ||
})).to.be.false; | ||
|
||
config.setConfig({ dailymotion: { api_key: 'test_api_key', position: 'test_position' } }); | ||
expect(spec.isBidRequestValid({ | ||
bidder: 'dailymotion', | ||
})).to.be.true; | ||
}); | ||
|
||
// Validate request generation with api key & position only | ||
it('validates buildRequests - with api key & position', () => { | ||
const dmConfig = { api_key: 'test_api_key', position: 'test_position' }; | ||
|
||
config.setConfig({ | ||
dailymotion: dmConfig, | ||
coppa: true, | ||
}); | ||
|
||
const bidRequestData = [{ | ||
adUnitCode: 'test_adunitcode', | ||
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', | ||
bidId: 123456, | ||
bidder: 'dailymotion', | ||
}]; | ||
|
||
const bidderRequestData = { | ||
uspConsent: '1YN-', | ||
gdprConsent: { | ||
consentString: 'xxx', | ||
gdprApplies: 1 | ||
}, | ||
}; | ||
|
||
const [request] = spec.buildRequests(bidRequestData, bidderRequestData); | ||
const { data: reqData } = request; | ||
|
||
expect(request.url).to.equal('https://pb.dmxleo.com'); | ||
expect(reqData.bidder_request).to.equal(bidderRequestData) | ||
expect(reqData.config).to.equal(dmConfig); | ||
expect(reqData.coppa).to.be.true; | ||
expect(reqData.request).to.equal(bidRequestData[0]); | ||
}); | ||
|
||
// Validate request generation with api key, position, xid | ||
it('validates buildRequests - with auth & xid', function () { | ||
const dmConfig = { | ||
api_key: 'test_api_key', | ||
position: 'test_position', | ||
xid: 'x123456', | ||
}; | ||
|
||
config.setConfig({ dailymotion: dmConfig }); | ||
|
||
const bidRequestData = [{ | ||
adUnitCode: 'test_adunitcode', | ||
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', | ||
bidId: 123456, | ||
bidder: 'dailymotion', | ||
}]; | ||
|
||
const bidderRequestData = { | ||
uspConsent: '1YN-', | ||
gdprConsent: { | ||
consentString: 'xxx', | ||
gdprApplies: 1 | ||
}, | ||
}; | ||
|
||
const [request] = spec.buildRequests(bidRequestData, bidderRequestData); | ||
const { data: reqData } = request; | ||
|
||
expect(request.url).to.equal('https://pb.dmxleo.com'); | ||
expect(reqData.bidder_request).to.equal(bidderRequestData) | ||
expect(reqData.config).to.equal(dmConfig); | ||
expect(reqData.coppa).to.equal(true); | ||
expect(reqData.request).to.equal(bidRequestData[0]); | ||
}); | ||
|
||
it('validates interpretResponse', function () { | ||
const bidRequest = { data: {} }; | ||
|
||
const serverResponse = { | ||
body: { | ||
ad: 'https://fakecacheserver/cache?uuid=1234', | ||
cacheId: '1234', | ||
cpm: 20.0, | ||
creativeId: '5678', | ||
currency: 'USD', | ||
dealId: 'deal123', | ||
nurl: 'https://bid/nurl', | ||
requestId: 'test_requestid', | ||
vastUrl: 'https://fakecacheserver/cache?uuid=1234', | ||
}, | ||
}; | ||
|
||
const bids = spec.interpretResponse(serverResponse, bidRequest); | ||
expect(bids).to.have.lengthOf(1); | ||
|
||
const [bid] = bids; | ||
expect(bid.ad).to.equal(serverResponse.body.ad); | ||
expect(bid.cacheId).to.equal(serverResponse.body.cacheId); | ||
expect(bid.cpm).to.equal(serverResponse.body.cpm); | ||
expect(bid.creativeId).to.equal(serverResponse.body.creativeId); | ||
expect(bid.currency).to.equal(serverResponse.body.currency); | ||
expect(bid.dealId).to.equal(serverResponse.body.dealId); | ||
expect(bid.nurl).to.equal(serverResponse.body.nurl); | ||
expect(bid.requestId).to.equal(serverResponse.body.requestId); | ||
expect(bid.vastUrl).to.equal(serverResponse.body.vastUrl); | ||
}); | ||
}); |
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.
Wait for email