-
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
Insticator Bid Adapter: add new bid adapter #7277
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
52d73d8
Added Insticator Bidder Adapter
ef52a60
Insticator Bidder Adapter fixes
05e88db
Insticator Bidder Adapter - updated example
886b75a
Insticator Bidder Adapter - add meta.advertiserDomains
c036429
Updated Prebig.js version
0be3938
minor change
33160a1
rerun circle ci build
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,280 @@ | ||
import { config } from '../src/config.js'; | ||
import { BANNER } from '../src/mediaTypes.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
import { | ||
deepAccess, | ||
generateUUID, | ||
logError, | ||
} from '../src/utils.js'; | ||
import { getStorageManager } from '../src/storageManager.js'; | ||
|
||
const BIDDER_CODE = 'insticator'; | ||
const ENDPOINT = 'https://ex.ingage.tech/v1/openrtb'; // production endpoint | ||
const USER_ID_KEY = 'hb_insticator_uid'; | ||
const USER_ID_COOKIE_EXP = 2592000000; // 30 days | ||
const BID_TTL = 300; // 5 minutes | ||
const GVLID = 910; | ||
|
||
export const storage = getStorageManager(GVLID, BIDDER_CODE); | ||
|
||
config.setDefaults({ | ||
insticator: { | ||
endpointUrl: ENDPOINT, | ||
bidTTL: BID_TTL, | ||
}, | ||
}); | ||
|
||
function getUserId() { | ||
let uid; | ||
|
||
if (storage.localStorageIsEnabled()) { | ||
uid = localStorage.getItem(USER_ID_KEY); | ||
} else { | ||
uid = storage.getCookie(USER_ID_KEY); | ||
} | ||
|
||
if (uid && uid.length !== 36) { | ||
uid = undefined; | ||
} | ||
|
||
return uid; | ||
} | ||
|
||
function setUserId(userId) { | ||
if (storage.localStorageIsEnabled()) { | ||
localStorage.setItem(USER_ID_KEY, userId); | ||
} | ||
|
||
if (storage.cookiesAreEnabled()) { | ||
const expires = new Date(Date.now() + USER_ID_COOKIE_EXP).toISOString(); | ||
storage.setCookie(USER_ID_KEY, userId, expires); | ||
} | ||
} | ||
|
||
function buildImpression(bidRequest) { | ||
const format = []; | ||
const sizes = | ||
deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes; | ||
|
||
for (const size of sizes) { | ||
format.push({ | ||
w: size[0], | ||
h: size[1], | ||
}); | ||
} | ||
|
||
return { | ||
id: bidRequest.bidId, | ||
tagid: bidRequest.adUnitCode, | ||
banner: { | ||
format, | ||
}, | ||
ext: { | ||
insticator: { | ||
adUnitId: bidRequest.params.adUnitId, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function buildDevice() { | ||
const device = { | ||
w: window.innerWidth, | ||
h: window.innerHeight, | ||
js: true, | ||
ext: { | ||
localStorage: storage.localStorageIsEnabled(), | ||
cookies: storage.cookiesAreEnabled(), | ||
}, | ||
}; | ||
|
||
const deviceConfig = config.getConfig('device'); | ||
|
||
if (typeof deviceConfig === 'object') { | ||
Object.assign(device, deviceConfig); | ||
} | ||
|
||
return device; | ||
} | ||
|
||
function buildRegs(bidderRequest) { | ||
if (bidderRequest.gdprConsent) { | ||
return { | ||
ext: { | ||
gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0, | ||
gdprConsentString: bidderRequest.gdprConsent.consentString, | ||
}, | ||
}; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
function buildUser() { | ||
const userId = getUserId() || generateUUID(); | ||
|
||
setUserId(userId); | ||
|
||
return { | ||
id: userId, | ||
}; | ||
} | ||
|
||
function buildRequest(validBidRequests, bidderRequest) { | ||
const req = { | ||
id: bidderRequest.bidderRequestId, | ||
tmax: bidderRequest.timeout, | ||
source: { | ||
fd: 1, | ||
tid: bidderRequest.auctionId, | ||
}, | ||
site: { | ||
domain: location.hostname, | ||
page: location.href, | ||
ref: bidderRequest.refererInfo.referer, | ||
}, | ||
device: buildDevice(), | ||
regs: buildRegs(bidderRequest), | ||
user: buildUser(), | ||
imp: validBidRequests.map((bidRequest) => buildImpression(bidRequest)), | ||
}; | ||
|
||
const params = config.getConfig('insticator.params'); | ||
|
||
if (params) { | ||
req.ext = { | ||
insticator: params, | ||
}; | ||
} | ||
|
||
return req; | ||
} | ||
|
||
function buildBid(bid, bidderRequest) { | ||
const originalBid = bidderRequest.bids.find((b) => b.bidId === bid.impid); | ||
|
||
return { | ||
requestId: bid.impid, | ||
creativeId: bid.crid, | ||
cpm: bid.price, | ||
currency: 'USD', | ||
netRevenue: true, | ||
ttl: bid.exp || config.getConfig('insticator.bidTTL') || BID_TTL, | ||
width: bid.w, | ||
height: bid.h, | ||
mediaType: 'banner', | ||
ad: bid.adm, | ||
adUnitCode: originalBid.adUnitCode, | ||
meta: { | ||
advertiserDomains: bid.bidADomain && bid.bidADomain.length ? bid.bidADomain : [] | ||
}, | ||
}; | ||
} | ||
|
||
function buildBidSet(seatbid, bidderRequest) { | ||
return seatbid.bid.map((bid) => buildBid(bid, bidderRequest)); | ||
} | ||
|
||
function validateSize(size) { | ||
return ( | ||
size instanceof Array && | ||
size.length === 2 && | ||
typeof size[0] === 'number' && | ||
typeof size[1] === 'number' | ||
); | ||
} | ||
|
||
function validateSizes(sizes) { | ||
return ( | ||
sizes instanceof Array && | ||
sizes.length > 0 && | ||
sizes.map(validateSize).reduce((a, b) => a && b, true) | ||
); | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
gvlid: GVLID, | ||
supportedMediaTypes: [BANNER], | ||
|
||
isBidRequestValid: function (bid) { | ||
if (!bid.params.adUnitId) { | ||
logError('insticator: missing adUnitId bid parameter'); | ||
return false; | ||
} | ||
|
||
if (!(BANNER in bid.mediaTypes)) { | ||
logError('insticator: expected banner in mediaTypes'); | ||
return false; | ||
} | ||
|
||
if ( | ||
!validateSizes(bid.sizes) && | ||
!validateSizes(bid.mediaTypes.banner.sizes) | ||
) { | ||
logError('insticator: banner sizes not specified or invalid'); | ||
return false; | ||
} | ||
|
||
return true; | ||
}, | ||
|
||
buildRequests: function (validBidRequests, bidderRequest) { | ||
const requests = []; | ||
let endpointUrl = config.getConfig('insticator.endpointUrl') || ENDPOINT; | ||
endpointUrl = endpointUrl.replace(/^http:/, 'https:'); | ||
|
||
if (validBidRequests.length > 0) { | ||
requests.push({ | ||
method: 'POST', | ||
url: endpointUrl, | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: true, | ||
}, | ||
data: JSON.stringify(buildRequest(validBidRequests, bidderRequest)), | ||
bidderRequest, | ||
}); | ||
} | ||
|
||
return requests; | ||
}, | ||
|
||
interpretResponse: function (serverResponse, request) { | ||
const bidderRequest = request.bidderRequest; | ||
const body = serverResponse.body; | ||
|
||
if (!body || body.id !== bidderRequest.bidderRequestId) { | ||
logError('insticator: response id does not match bidderRequestId'); | ||
return []; | ||
} | ||
|
||
if (!body.seatbid) { | ||
return []; | ||
} | ||
|
||
const bidsets = body.seatbid.map((seatbid) => | ||
buildBidSet(seatbid, bidderRequest) | ||
); | ||
|
||
return bidsets.reduce((a, b) => a.concat(b), []); | ||
}, | ||
|
||
getUserSyncs: function (options, responses) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you wanna check here for Gdpr and Usp consent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We check the GDPR and USP consent on the backend side and pass them via ext.sync. |
||
const syncs = []; | ||
|
||
for (const response of responses) { | ||
if ( | ||
response.body && | ||
response.body.ext && | ||
response.body.ext.sync instanceof Array | ||
) { | ||
syncs.push(...response.body.ext.sync); | ||
} | ||
} | ||
|
||
return syncs; | ||
}, | ||
}; | ||
|
||
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,53 @@ | ||
Overview | ||
======== | ||
|
||
``` | ||
Module Name: Insticator Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: [email protected] | ||
``` | ||
|
||
Description | ||
=========== | ||
|
||
This module connects publishers to Insticator exchange of demand sources through Prebid.js. | ||
|
||
### Supported Media Types | ||
|
||
| Type | Support | ||
| --- | --- | ||
| Banner | Fully supported for all approved sizes. | ||
|
||
# Bid Parameters | ||
|
||
Each of the Insticator-specific parameters provided under the `adUnits[].bids[].params` | ||
object are detailed here. | ||
|
||
### Banner | ||
|
||
| Key | Scope | Type | Description | ||
| --- | --- | --- | --- | ||
| adUnitId | Required | String | The ad unit ID provided by Insticator. | ||
|
||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
{ | ||
code: 'test-div', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250], [300, 600]] | ||
} | ||
}, | ||
bids: [ | ||
{ | ||
bidder: 'insticator', | ||
params: { | ||
adUnitId: 'test' | ||
} | ||
} | ||
] | ||
} | ||
] | ||
``` |
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.
You can include the
gvlid
property in thespec
object.