-
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
Blue Bid Adapter : initial release #12513
Open
maqtulio
wants to merge
27
commits into
prebid:master
Choose a base branch
from
maqtulio:feature/add-blue
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ab55073
add blue
tulio-bms fb57fb1
uncommited stuff
tulio-bms d69a4c2
uncommited stuff
tulio-bms e29efa1
uncommited stuff
tulio-bms a9f8712
Merge branch 'master' into feature/add-blue
tulio-bms 5c18e1b
less duplicated code
tulio-bms 6ac6a61
less duplicated code
tulio-bms 968b798
less duplicated code
tulio-bms 8207721
less duplicated code
tulio-bms b980c32
less duplicated code
tulio-bms 64b502a
blue adapter
tulio-bms 21d5b27
blue adapter
tulio-bms 7df2bdd
blue adapter
tulio-bms 7647cc6
blue adapter
tulio-bms 51faf45
blue adapter
tulio-bms 1998e5c
blue adapter
tulio-bms 53334f3
blue adapter
tulio-bms 8e42e5a
blue adapter
tulio-bms dacf41c
blue adapter
tulio-bms 824e59f
blue adapter
tulio-bms 2c9cbe4
blue adapter
tulio-bms e0ec287
add floor module support
tulio-bms af8ea37
add floor module support
tulio-bms 844bac5
add floor module support
tulio-bms d4490c3
add floor module support
tulio-bms b8baf31
add floor module support
tulio-bms 4cd7a21
only import what we need
tulio-bms 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,122 @@ | ||
import { ortbConverter } from '../libraries/ortbConverter/converter.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
import { deepSetValue, isFn, isPlainObject } from '../src/utils.js'; | ||
|
||
const BIDDER_CODE = 'blue'; | ||
const ENDPOINT_URL = 'https://bidder-us-east-1.getblue.io/engine/?src=prebid'; | ||
const GVLID = 620; // GVLID for your bidder | ||
const COOKIE_NAME = 'ckid'; // Cookie name for identifying users | ||
const CURRENCY = 'USD'; // Currency used in bid floors | ||
|
||
export const storage = getStorageManager({ bidderCode: BIDDER_CODE }); | ||
|
||
const converter = ortbConverter({ | ||
context: { | ||
netRevenue: true, // Default netRevenue setting | ||
ttl: 100, // Default time-to-live for bid responses | ||
}, | ||
imp, | ||
request, | ||
}); | ||
|
||
function request(buildRequest, imps, bidderRequest, context) { | ||
let request = buildRequest(imps, bidderRequest, context); | ||
deepSetValue(request, 'site.publisher.id', context.publisherId); | ||
return request; | ||
} | ||
|
||
function imp(buildImp, bidRequest, context) { | ||
const imp = buildImp(bidRequest, context); | ||
const floor = getBidFloor(bidRequest); | ||
if (floor) { | ||
imp.bidfloor = floor; | ||
imp.bidfloorcur = CURRENCY; | ||
} | ||
return imp; | ||
} | ||
|
||
function getBidFloor(bid) { | ||
if (isFn(bid.getFloor)) { | ||
let floor = bid.getFloor({ | ||
currency: CURRENCY, | ||
mediaType: BANNER, | ||
size: '*', | ||
}); | ||
if ( | ||
isPlainObject(floor) && | ||
!isNaN(floor.floor) && | ||
floor.currency === CURRENCY | ||
) { | ||
return floor.floor; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
gvlid: GVLID, | ||
supportedMediaTypes: [BANNER], // Supported ad types | ||
|
||
// Validate bid request | ||
isBidRequestValid: function (bid) { | ||
return !!bid.params.placementId && !!bid.params.publisherId; | ||
}, | ||
|
||
// Build OpenRTB requests using `ortbConverter` | ||
buildRequests: function (validBidRequests, bidderRequest) { | ||
const context = { | ||
publisherId: validBidRequests.find( | ||
(bidRequest) => bidRequest.params?.publisherId | ||
)?.params.publisherId, | ||
}; | ||
|
||
const ortbRequest = converter.toORTB({ | ||
bidRequests: validBidRequests, | ||
bidderRequest, | ||
context, | ||
}); | ||
|
||
// Add GVLID and cookie ID to the request | ||
ortbRequest.ext = ortbRequest.ext || {}; | ||
deepSetValue(ortbRequest, 'ext.gvlid', GVLID); | ||
|
||
// Include user cookie if available | ||
const ckid = storage.getDataFromLocalStorage('blueID') || storage.getCookie(COOKIE_NAME) || null; | ||
if (ckid) { | ||
deepSetValue(ortbRequest, 'user.ext.buyerid', ckid); | ||
} | ||
|
||
return { | ||
method: 'POST', | ||
url: ENDPOINT_URL, | ||
data: JSON.stringify(ortbRequest), | ||
options: { | ||
contentType: 'text/plain', | ||
}, | ||
}; | ||
}, | ||
|
||
// Interpret OpenRTB responses using `ortbConverter` | ||
interpretResponse: function (serverResponse, request) { | ||
const ortbResponse = serverResponse.body; | ||
|
||
// Parse the OpenRTB response into Prebid bid responses | ||
const prebidResponses = converter.fromORTB({ | ||
response: ortbResponse, | ||
request: request.data, | ||
}).bids; | ||
|
||
// Example: Modify bid responses if needed | ||
prebidResponses.forEach((bid) => { | ||
bid.meta = bid.meta || {}; | ||
bid.meta.adapterVersion = '1.0.0'; | ||
}); | ||
|
||
return prebidResponses; | ||
}, | ||
}; | ||
|
||
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,28 @@ | ||
# Overview | ||
|
||
Module Name: Blue Bidder Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Module that connects to Blue's demand sources. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'banner-ad-div', | ||
sizes: [[300, 250], [728, 90]], | ||
bids: [ | ||
{ | ||
bidder: 'blue', | ||
params: { | ||
publisherId: "xpto", | ||
placementId: "xpto", | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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,91 @@ | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
import { spec, storage } from 'modules/blueBidAdapter.js'; | ||
|
||
const BIDDER_CODE = 'blue'; | ||
const ENDPOINT_URL = 'https://bidder-us-east-1.getblue.io/engine/?src=prebid'; | ||
const GVLID = 620; | ||
const COOKIE_NAME = 'ckid'; | ||
const CURRENCY = 'USD'; | ||
|
||
describe('blueBidAdapter:', function () { | ||
let sandbox; | ||
|
||
beforeEach(function () { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('isBidRequestValid:', function () { | ||
it('should return true for valid bid requests', function () { | ||
const validBid = { | ||
params: { | ||
placementId: '12345', | ||
publisherId: '67890', | ||
}, | ||
}; | ||
expect(spec.isBidRequestValid(validBid)).to.be.true; | ||
}); | ||
|
||
it('should return false for invalid bid requests', function () { | ||
const invalidBid = { | ||
params: { | ||
placementId: '12345', | ||
}, | ||
}; | ||
expect(spec.isBidRequestValid(invalidBid)).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('buildRequests:', function () { | ||
let validBidRequests; | ||
let bidderRequest; | ||
|
||
beforeEach(function () { | ||
validBidRequests = [ | ||
{ | ||
bidId: 'bid1', | ||
params: { | ||
placementId: '12345', | ||
publisherId: '67890', | ||
}, | ||
getFloor: () => ({ currency: CURRENCY, floor: 1.5 }), | ||
}, | ||
]; | ||
|
||
bidderRequest = { | ||
refererInfo: { | ||
page: 'https://example.com', | ||
}, | ||
}; | ||
|
||
sandbox.stub(storage, 'getDataFromLocalStorage').returns('testBuyerId'); | ||
}); | ||
|
||
it('should build a valid OpenRTB request', function () { | ||
const request = spec.buildRequests(validBidRequests, bidderRequest); | ||
|
||
expect(request.method).to.equal('POST'); | ||
expect(request.url).to.equal(ENDPOINT_URL); | ||
expect(request.options.contentType).to.equal('test/plain'); | ||
|
||
const ortbRequest = JSON.parse(request.data); | ||
expect(ortbRequest.ext.gvlid).to.equal(GVLID); | ||
expect(ortbRequest.user.ext.buyerid).to.equal('testBuyerId'); | ||
expect(ortbRequest.imp[0].bidfloor).to.equal(1.5); | ||
expect(ortbRequest.imp[0].bidfloorcur).to.equal(CURRENCY); | ||
}); | ||
|
||
it('should omit bidfloor if getFloor is not implemented', function () { | ||
validBidRequests[0].getFloor = undefined; | ||
|
||
const request = spec.buildRequests(validBidRequests, bidderRequest); | ||
const ortbRequest = JSON.parse(request.data); | ||
|
||
expect(ortbRequest.imp[0].bidfloor).to.be.undefined; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
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.
Your typo here is why your tests keep failing