-
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
1.0 adapter support for mantis #1840
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 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,206 @@ | ||
import {registerBidder} from 'src/adapters/bidderFactory'; | ||
|
||
function inIframe() { | ||
try { | ||
return window.self !== window.top && !window.mantis_link; | ||
} catch (e) { | ||
return true; | ||
} | ||
} | ||
|
||
function isDesktop(ignoreTouch) { | ||
var supportsTouch = !ignoreTouch && ('ontouchstart' in window || navigator.msMaxTouchPoints); | ||
if (inIframe()) { | ||
return !supportsTouch; | ||
} | ||
var width = window.innerWidth || window.document.documentElement.clientWidth || window.document.body.clientWidth; | ||
return !supportsTouch && (!width || width >= (window.mantis_breakpoint || 768)); | ||
} | ||
|
||
function storeUuid(uuid) { | ||
if (window.mantis_uuid) { | ||
return false; | ||
} | ||
window.mantis_uuid = uuid; | ||
if (window.localStorage) { | ||
try { | ||
window.localStorage.setItem('mantis:uuid', uuid); | ||
} catch (ex) { | ||
} | ||
} | ||
} | ||
|
||
function isSendable(val) { | ||
if (val === null || val === undefined) { | ||
return false; | ||
} | ||
if (typeof val === 'string') { | ||
return !(!val || /^\s*$/.test(val)); | ||
} | ||
if (typeof val === 'number') { | ||
return !isNaN(val); | ||
} | ||
return true; | ||
} | ||
|
||
function isObject(value) { | ||
return Object.prototype.toString.call(value) === '[object Object]'; | ||
} | ||
|
||
function isAmp() { | ||
return typeof window.context === 'object' && (window.context.tagName === 'AMP-AD' || window.context.tagName === 'AMP-EMBED'); | ||
} | ||
|
||
function isSecure() { | ||
return document.location.protocol === 'https:'; | ||
} | ||
|
||
function isArray(value) { | ||
return Object.prototype.toString.call(value) === '[object Array]'; | ||
} | ||
|
||
function jsonToQuery(data, chain, form) { | ||
if (!data) { | ||
return null; | ||
} | ||
var parts = form || []; | ||
for (var key in data) { | ||
var queryKey = key; | ||
if (chain) { | ||
queryKey = chain + '[' + key + ']'; | ||
} | ||
var val = data[key]; | ||
if (isArray(val)) { | ||
for (var index = 0; index < val.length; index++) { | ||
var akey = queryKey + '[' + index + ']'; | ||
var aval = val[index]; | ||
if (isObject(aval)) { | ||
jsonToQuery(aval, akey, parts); | ||
} else if (isSendable(aval)) { | ||
parts.push(akey + '=' + encodeURIComponent(aval)); | ||
} | ||
} | ||
} else if (isObject(val) && val != data) { | ||
jsonToQuery(val, queryKey, parts); | ||
} else if (isSendable(val)) { | ||
parts.push(queryKey + '=' + encodeURIComponent(val)); | ||
} | ||
} | ||
return parts.join('&'); | ||
} | ||
|
||
function buildMantisUrl(path, data, domain) { | ||
var params = { | ||
referrer: document.referrer, | ||
tz: new Date().getTimezoneOffset(), | ||
buster: new Date().getTime(), | ||
secure: isSecure() | ||
}; | ||
if (!inIframe() || isAmp()) { | ||
params.mobile = !isAmp() && isDesktop(true) ? 'false' : 'true'; | ||
} | ||
if (window.mantis_uuid) { | ||
params.uuid = window.mantis_uuid; | ||
} else if (window.localStorage) { | ||
var localUuid = window.localStorage.getItem('mantis:uuid'); | ||
if (localUuid) { | ||
params.uuid = localUuid; | ||
} | ||
} | ||
if (!inIframe()) { | ||
try { | ||
params.title = window.top.document.title; | ||
params.referrer = window.top.document.referrer; | ||
params.url = window.top.document.location.href; | ||
} catch (ex) { | ||
} | ||
} else { | ||
params.iframe = true; | ||
} | ||
if (isAmp()) { | ||
params.amp = true; | ||
if (!params.url && window.context.canonicalUrl) { | ||
params.url = window.context.canonicalUrl; | ||
} | ||
if (!params.url && window.context.location) { | ||
params.url = window.context.location.href; | ||
} | ||
if (!params.referrer && window.context.referrer) { | ||
params.referrer = window.context.referrer; | ||
} | ||
} | ||
Object.keys(data || {}).forEach(function (key) { | ||
params[key] = data[key]; | ||
}); | ||
var query = jsonToQuery(params); | ||
return (window.mantis_domain === undefined ? domain || 'https://mantodea.mantisadnetwork.com' : window.mantis_domain) + path + '?' + query; | ||
} | ||
|
||
const spec = { | ||
code: 'mantis', | ||
supportedMediaTypes: ['banner', 'video', 'native'], | ||
isBidRequestValid: function (bid) { | ||
return !!(bid.params.property && (bid.params.code || bid.params.zoneId || bid.params.zone)); | ||
}, | ||
buildRequests: function (validBidRequests) { | ||
var property = null; | ||
validBidRequests.some(function (bid) { | ||
if (bid.params.property) { | ||
property = bid.params.property; | ||
return true; | ||
} | ||
}); | ||
const query = { | ||
bids: validBidRequests.map(function (bid) { | ||
return { | ||
bidId: bid.bidId, | ||
config: bid.params, | ||
sizes: bid.sizes.map(function (size) { | ||
return {width: size[0], height: size[1]}; | ||
}) | ||
}; | ||
}), | ||
property: property, | ||
version: 2 | ||
}; | ||
return { | ||
method: 'GET', | ||
url: buildMantisUrl('/prebid/display', query) + '&foo', | ||
data: '' | ||
}; | ||
}, | ||
interpretResponse: function (serverResponse) { | ||
storeUuid(serverResponse.uuid); | ||
return serverResponse.body.ads.map(function (ad) { | ||
return { | ||
requestId: ad.bid, | ||
cpm: ad.cpm, | ||
width: ad.width, | ||
height: ad.height, | ||
ad: ad.html, | ||
ttl: 86400, | ||
creativeId: ad.view, | ||
netRevenue: true, | ||
currency: 'USD' | ||
}; | ||
}); | ||
}, | ||
getUserSyncs: function (syncOptions) { | ||
if (syncOptions.iframeEnabled) { | ||
return [{ | ||
type: 'iframe', | ||
url: buildMantisUrl('/prebid/iframe') | ||
}]; | ||
} | ||
if (syncOptions.pixelEnabled) { | ||
return [{ | ||
type: 'image', | ||
url: buildMantisUrl('/prebid/pixel') | ||
}]; | ||
} | ||
} | ||
}; | ||
|
||
export {spec}; | ||
|
||
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,30 @@ | ||
# Overview | ||
|
||
Module Name: MANTIS Ad Network Bid Adapter | ||
|
||
Module Type: Bidder Adapter | ||
|
||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Module that connects to MANTIS's demand sources | ||
|
||
# Test Parameters | ||
```javascript | ||
var adUnits = [ | ||
{ | ||
code: 'test', | ||
sizes: [[300, 250]], | ||
bids: [ | ||
{ | ||
bidder: 'mantis', | ||
params: { | ||
property: 'demo', | ||
zone: 'zone' | ||
} | ||
} | ||
] | ||
} | ||
]; | ||
``` |
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.
Note: There is a function for testing types included in utils.js beginning on line #332. Line #334 includes an "isArray" method where you can see how the "isA" method could be used for testing types not included such as "[Object]".