-
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
Displayio Bid Adapter: custom render; fix eids payload #8847
Merged
patmmccann
merged 2 commits into
prebid:master
from
philan15:displayio-bid-adapter-custom-render
Aug 19, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
import {registerBidder} from '../src/adapters/bidderFactory.js'; | ||
import {BANNER, VIDEO} from '../src/mediaTypes.js'; | ||
import {Renderer} from '../src/Renderer.js'; | ||
import {getWindowFromDocument, logWarn, deepAccess} from '../src/utils.js'; | ||
import {createEidsArray} from './userId/eids.js'; | ||
|
||
const BIDDER_VERSION = '1.0.0'; | ||
const BIDDER_CODE = 'displayio'; | ||
|
@@ -20,7 +23,7 @@ export const spec = { | |
return bidRequests.map(bid => { | ||
let url = '//' + bid.params.adsSrvDomain + '/srv?method=getPlacement&app=' + | ||
bid.params.siteId + '&placement=' + bid.params.placementId; | ||
const data = this._getPayload(bid, bidderRequest); | ||
const data = getPayload(bid, bidderRequest); | ||
return { | ||
method: 'POST', | ||
headers: {'Content-Type': 'application/json;charset=utf-8'}, | ||
|
@@ -42,117 +45,112 @@ export const spec = { | |
height: adData.h, | ||
netRevenue: true, | ||
ttl: BID_TTL, | ||
creativeId: adData.adId || 0, | ||
currency: DEFAULT_CURRENCY, | ||
creativeId: adData.adId || 1, | ||
currency: adData.cur || DEFAULT_CURRENCY, | ||
referrer: data.data.ref, | ||
mediaType: ads[0].ad.subtype, | ||
mediaType: ads[0].ad.subtype === 'videoVast' ? VIDEO : BANNER, | ||
ad: adData.markup, | ||
placement: data.placement, | ||
adUnitCode: data.adUnitCode, | ||
renderURL: data.renderURL, | ||
adData: adData | ||
}; | ||
if (bidResponse.vastUrl === 'videoVast') { | ||
bidResponse.vastUrl = adData.videos[0].url | ||
|
||
if (bidResponse.mediaType === VIDEO) { | ||
bidResponse.vastUrl = adData.videos[0] && adData.videos[0].url | ||
} | ||
|
||
if (bidResponse.renderURL) { | ||
bidResponse.renderer = newRenderer(bidResponse); | ||
} | ||
bidResponses.push(bidResponse); | ||
} | ||
return bidResponses; | ||
}, | ||
_getPayload: function (bid, bidderRequest) { | ||
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; | ||
const userSession = 'us_web_xxxxxxxxxxxx'.replace(/[x]/g, c => { | ||
let r = Math.random() * 16 | 0; | ||
let v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
const { params } = bid; | ||
const { siteId, placementId } = params; | ||
const { refererInfo, uspConsent, gdprConsent } = bidderRequest; | ||
const mediation = {consent: '-1', gdpr: '-1'}; | ||
if (gdprConsent) { | ||
if (gdprConsent.consentString !== undefined) { | ||
mediation.consent = gdprConsent.consentString; | ||
} | ||
if (gdprConsent.gdprApplies !== undefined) { | ||
mediation.gdpr = gdprConsent.gdprApplies ? '1' : '0'; | ||
} | ||
} | ||
}; | ||
|
||
function getPayload (bid, bidderRequest) { | ||
const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; | ||
const userSession = 'us_web_xxxxxxxxxxxx'.replace(/[x]/g, c => { | ||
let r = Math.random() * 16 | 0; | ||
let v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
const { params, adUnitCode, bidId } = bid; | ||
const { siteId, placementId, renderURL, pageCategory, keywords } = params; | ||
const { refererInfo, uspConsent, gdprConsent } = bidderRequest; | ||
const mediation = {consent: '-1', gdpr: '-1'}; | ||
if (gdprConsent && 'gdprApplies' in gdprConsent) { | ||
if (gdprConsent.consentString !== undefined) { | ||
mediation.consent = gdprConsent.consentString; | ||
} | ||
const payload = { | ||
userSession, | ||
if (gdprConsent.gdprApplies !== undefined) { | ||
mediation.gdpr = gdprConsent.gdprApplies ? '1' : '0'; | ||
} | ||
} | ||
return { | ||
userSession, | ||
data: { | ||
id: bidId, | ||
action: 'getPlacement', | ||
app: siteId, | ||
placement: placementId, | ||
adUnitCode, | ||
renderURL, | ||
data: { | ||
id: bid.bidId, | ||
action: 'getPlacement', | ||
app: siteId, | ||
placement: placementId, | ||
data: { | ||
pagecat: params.pageCategory ? params.pageCategory.split(',').map(k => k.trim()) : [], | ||
keywords: params.keywords ? params.keywords.split(',').map(k => k.trim()) : [], | ||
lang_content: document.documentElement.lang, | ||
lang: window.navigator.language, | ||
// TODO: are these the correct refererInfo values? | ||
domain: refererInfo.domain, | ||
page: refererInfo.page, | ||
ref: refererInfo.ref, | ||
userids: _getUserIDs(), | ||
geo: '', | ||
}, | ||
complianceData: { | ||
child: '-1', | ||
us_privacy: uspConsent, | ||
dnt: window.navigator.doNotTrack, | ||
iabConsent: {}, | ||
mediation: { | ||
consent: mediation.consent, | ||
gdpr: mediation.gdpr, | ||
} | ||
}, | ||
integration: 'JS', | ||
omidpn: 'Displayio', | ||
mediationPlatform: 0, | ||
prebidVersion: BIDDER_VERSION, | ||
device: { | ||
w: window.screen.width, | ||
h: window.screen.height, | ||
connection_type: connection ? connection.effectiveType : '', | ||
pagecat: pageCategory ? pageCategory.split(',').map(k => k.trim()) : [], | ||
keywords: keywords ? keywords.split(',').map(k => k.trim()) : [], | ||
lang_content: document.documentElement.lang, | ||
lang: window.navigator.language, | ||
domain: window.location.hostname, | ||
page: window.location.href, | ||
ref: refererInfo.referer, | ||
userids: deepAccess(bid, 'userId') ? createEidsArray(bid.userId) : {}, | ||
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. you shouldn't need to import createEidsArray. The output of this function is already on the bid request 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. @patmmccann Thank you for help! fixed |
||
geo: '', | ||
}, | ||
complianceData: { | ||
child: '-1', | ||
us_privacy: uspConsent, | ||
dnt: window.doNotTrack === '1' || window.navigator.doNotTrack === '1' || false, | ||
iabConsent: {}, | ||
mediation: { | ||
consent: mediation.consent, | ||
gdpr: mediation.gdpr, | ||
} | ||
}, | ||
integration: 'JS', | ||
omidpn: 'Displayio', | ||
mediationPlatform: 0, | ||
prebidVersion: BIDDER_VERSION, | ||
device: { | ||
w: window.screen.width, | ||
h: window.screen.height, | ||
connection_type: connection ? connection.effectiveType : '', | ||
} | ||
} | ||
if (navigator.permissions) { | ||
navigator.permissions.query({ name: 'geolocation' }) | ||
.then((result) => { | ||
if (result.state === 'granted') { | ||
payload.data.data.geo = _getGeoData(); | ||
} | ||
}); | ||
} | ||
return payload | ||
} | ||
}; | ||
} | ||
|
||
function newRenderer(bid) { | ||
const renderer = Renderer.install({ | ||
id: bid.requestId, | ||
url: bid.renderURL, | ||
adUnitCode: bid.adUnitCode | ||
}); | ||
|
||
function _getUserIDs () { | ||
let ids = {}; | ||
try { | ||
ids = window.owpbjs.getUserIdsAsEids(); | ||
} catch (e) {} | ||
return ids; | ||
renderer.setRender(webisRender); | ||
} catch (err) { | ||
logWarn('Prebid Error calling setRender on renderer', err); | ||
} | ||
|
||
return renderer; | ||
} | ||
|
||
async function _getGeoData () { | ||
let geoData = null; | ||
const getCurrentPosition = () => { | ||
return new Promise((resolve, reject) => | ||
navigator.geolocation.getCurrentPosition(resolve, reject) | ||
); | ||
} | ||
try { | ||
const position = await getCurrentPosition(); | ||
let {latitude, longitude, accuracy} = position.coords; | ||
geoData = { | ||
'lat': latitude, | ||
'lng': longitude, | ||
'precision': accuracy | ||
}; | ||
} catch (e) {} | ||
return geoData | ||
function webisRender(bid, doc) { | ||
bid.renderer.push(() => { | ||
const win = getWindowFromDocument(doc) || window; | ||
win.webis.init(bid.adData, bid.adUnitCode, bid.params); | ||
}) | ||
} | ||
|
||
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
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.
why not refererInfo.page