-
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
Update ucfunnelBidAdapter #1990
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d18db95
Add a new ucfunnel Adapter and test page
f82a4b7
Add a new ucfunnel Adapter and test page
4c91775
1. Use prebid lib in the repo to keep updated
RyanChouTw 52eaecb
Merge branch 'master' into master
RyanChouTw 96a70a4
utils.getTopWindowLocation is a function
RyanChouTw 7202a62
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw 858b833
Change to modules from adapters
RyanChouTw 8b46932
Migrate to module design
RyanChouTw d7e043b
[Dev Fix] Remove width and height which can be got from ad unit id
RyanChouTw badfa53
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw 8d81704
Merge pull request #1 from prebid/master
RyanChouTw 8e7fe31
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw 5dc00f3
Update ucfunnelBidAdapter to fit into new spec
RyanChouTw 66c3a06
Correct the endpoint. Fix the error of query string
RyanChouTw 0328e97
Add test case for ucfunnelBidAdapter
RyanChouTw c2c5eb0
Merge branch 'master' of https://github.com/prebid/Prebid.js
RyanChouTw 86fdd23
Fix lint error
RyanChouTw c331f57
Update version number
RyanChouTw 28acb40
Combine all checks on bid request
RyanChouTw 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,95 @@ | ||
import * as utils from 'src/utils'; | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
import { BANNER } from 'src/mediaTypes'; | ||
|
||
const VER = 'ADGENT_PREBID-2018011501'; | ||
const BID_REQUEST_BASE_URL = '//hb.aralego.com/header'; | ||
const UCFUNNEL_BIDDER_CODE = 'ucfunnel'; | ||
|
||
export const spec = { | ||
code: UCFUNNEL_BIDDER_CODE, | ||
supportedMediaTypes: [BANNER], | ||
/** | ||
* Check if the bid is a valid zone ID in either number or string form | ||
* @param {object} bid the ucfunnel bid to validate | ||
* @return boolean for whether or not a bid is valid | ||
*/ | ||
isBidRequestValid: function(bid) { | ||
return !!(bid && bid.params && bid.params.adid && typeof bid.params.adid === 'string'); | ||
}, | ||
|
||
/** | ||
* Format the bid request object for our endpoint | ||
* @param {BidRequest[]} bidRequests Array of ucfunnel bidders | ||
* @return object of parameters for Prebid AJAX request | ||
*/ | ||
buildRequests: function(validBidRequests) { | ||
var bidRequests = []; | ||
for (var i = 0; i < validBidRequests.length; i++) { | ||
var bid = validBidRequests[i]; | ||
|
||
var ucfunnelUrlParams = buildUrlParams(bid); | ||
|
||
bidRequests.push({ | ||
method: 'GET', | ||
url: BID_REQUEST_BASE_URL, | ||
bidRequest: bid, | ||
data: ucfunnelUrlParams | ||
}); | ||
} | ||
return bidRequests; | ||
}, | ||
|
||
/** | ||
* Format ucfunnel responses as Prebid bid responses | ||
* @param {ucfunnelResponseObj} ucfunnelResponse A successful response from ucfunnel. | ||
* @return {Bid[]} An array of formatted bids. | ||
*/ | ||
interpretResponse: function (ucfunnelResponseObj, request) { | ||
var bidResponses = []; | ||
var bidRequest = request.bidRequest; | ||
var responseBody = ucfunnelResponseObj ? ucfunnelResponseObj.body : {}; | ||
|
||
bidResponses.push({ | ||
requestId: bidRequest.bidId, | ||
cpm: responseBody.cpm || 0, | ||
width: responseBody.width, | ||
height: responseBody.height, | ||
creativeId: responseBody.ad_id, | ||
dealId: responseBody.deal || null, | ||
currency: 'USD', | ||
netRevenue: true, | ||
ttl: 1000, | ||
mediaType: BANNER, | ||
ad: responseBody.adm | ||
}); | ||
|
||
return bidResponses; | ||
} | ||
}; | ||
registerBidder(spec); | ||
|
||
function buildUrlParams(bid) { | ||
const host = utils.getTopWindowLocation().host; | ||
const page = utils.getTopWindowLocation().pathname; | ||
const refer = document.referrer; | ||
const language = navigator.language; | ||
const dnt = (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0; | ||
|
||
let queryString = [ | ||
'ifr', '0', | ||
'bl', language, | ||
'je', '1', | ||
'dnt', dnt, | ||
'host', host, | ||
'u', page, | ||
'ru', refer, | ||
'adid', utils.getBidIdParameter('adid', bid.params), | ||
'ver', VER | ||
]; | ||
|
||
return queryString.reduce( | ||
(memo, curr, index) => | ||
index % 2 === 0 && queryString[index + 1] !== undefined ? memo + curr + '=' + encodeURIComponent(queryString[index + 1]) + '&' : memo, '' | ||
).slice(0, -1); | ||
} |
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,30 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: ucfunnel Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: ryan.chou@ucfunnel.com | ||
``` | ||
|
||
# Description | ||
|
||
This module connects to ucfunnel's demand sources. It supports display, and rich media formats. | ||
ucfunnel will provide ``adid`` that are specific to your ad type. | ||
Please reach out to ``pr@ucfunnel.com`` to set up an ucfunnel account and above ids. | ||
Use bidder code ```ucfunnel``` for all ucfunnel traffic. | ||
|
||
# Test Parameters | ||
|
||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-LERC', | ||
sizes: [[300, 250]], | ||
bids: [{ | ||
bidder: 'ucfunnel', | ||
params: { | ||
adid: "test-ad-83444226E44368D1E32E49EEBE6D29" //String - required | ||
} | ||
} | ||
]; | ||
``` |
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,114 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/ucfunnelBidAdapter'; | ||
|
||
const URL = '//hb.aralego.com/header'; | ||
const BIDDER_CODE = 'ucfunnel'; | ||
const validBidReq = { | ||
bidder: BIDDER_CODE, | ||
params: { | ||
adid: 'test-ad-83444226E44368D1E32E49EEBE6D29' | ||
}, | ||
sizes: [[300, 250]], | ||
bidId: '263be71e91dd9d', | ||
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', | ||
}; | ||
|
||
const invalidBidReq = { | ||
bidder: BIDDER_CODE, | ||
params: { | ||
adid: 123456789 | ||
}, | ||
sizes: [[300, 250]], | ||
bidId: '263be71e91dd9d', | ||
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' | ||
}; | ||
|
||
const bidReq = [{ | ||
bidder: BIDDER_CODE, | ||
params: { | ||
adid: 'test-ad-83444226E44368D1E32E49EEBE6D29' | ||
}, | ||
sizes: [[300, 250]], | ||
bidId: '263be71e91dd9d', | ||
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' | ||
}]; | ||
|
||
const validBidRes = { | ||
ad_id: 'ad-83444226E44368D1E32E49EEBE6D29', | ||
adm: '<html style="height:100%"><body style="width:300px;height: 100%;padding:0;margin:0 auto;"><div style="width:100%;height:100%;display:table;"><div style="width:100%;height:100%;display:table-cell;text-align:center;vertical-align:middle;"><a href="//www.ucfunnel.com/" target="_blank"><img src="//cdn.aralego.net/ucfad/house/ucf/AdGent-300x250.jpg" width="300px" height="250px" align="middle" style="border:none"></a></div></div></body></html>', | ||
cpm: 0.01, | ||
height: 250, | ||
width: 300 | ||
}; | ||
|
||
const bidResponse = validBidRes; | ||
|
||
const bidResArray = [ | ||
validBidRes, | ||
{ | ||
ad: '', | ||
bidRequestId: '263be71e91dd9d', | ||
cpm: 100, | ||
adId: '123abc', | ||
currency: 'USD', | ||
netRevenue: true, | ||
width: 300, | ||
height: 250, | ||
ttl: 360 | ||
}, | ||
{ | ||
ad: '<div>Hello</div>', | ||
bidRequestId: '', | ||
cpm: 0, | ||
adId: '123abc', | ||
currency: 'USD', | ||
netRevenue: true, | ||
width: 300, | ||
height: 250, | ||
ttl: 360 | ||
} | ||
]; | ||
|
||
describe('ucfunnel Adapter', () => { | ||
describe('request', () => { | ||
it('should validate bid request', () => { | ||
expect(spec.isBidRequestValid(validBidReq)).to.equal(true); | ||
}); | ||
it('should not validate incorrect bid request', () => { | ||
expect(spec.isBidRequestValid(invalidBidReq)).to.equal(false); | ||
}); | ||
}); | ||
describe('build request', () => { | ||
it('bidRequest method', () => { | ||
const request = spec.buildRequests(bidReq); | ||
expect(request[0].method).to.equal('GET'); | ||
}); | ||
it('bidRequest url', () => { | ||
const request = spec.buildRequests(bidReq); | ||
expect(request[0].url).to.equal(URL); | ||
}); | ||
it('bidRequest data', () => { | ||
const request = spec.buildRequests(bidReq); | ||
expect(request[0].data).to.match(new RegExp(`${bidReq[0].params.adid}`)); | ||
}); | ||
}); | ||
|
||
describe('interpretResponse', () => { | ||
it('should build bid array', () => { | ||
const request = spec.buildRequests(bidReq); | ||
const result = spec.interpretResponse({body: bidResponse}, request[0]); | ||
expect(result.length).to.equal(1); | ||
}); | ||
|
||
it('should have all relevant fields', () => { | ||
const request = spec.buildRequests(bidReq); | ||
const result = spec.interpretResponse({body: bidResponse}, request[0]); | ||
const bid = result[0]; | ||
|
||
expect(bid.requestId).to.equal('263be71e91dd9d'); | ||
expect(bid.cpm).to.equal(0.01); | ||
expect(bid.width).to.equal(300); | ||
expect(bid.height).to.equal(250); | ||
}); | ||
}); | ||
}); |
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.
There's no reason this needs to be three separate tests. It will just make the test suite run longer for no discernible reason.