Skip to content
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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 92 additions & 94 deletions modules/displayioBidAdapter.js
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';
Expand All @@ -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'},
Expand All @@ -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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not refererInfo.page

ref: refererInfo.referer,
userids: deepAccess(bid, 'userId') ? createEidsArray(bid.userId) : {},
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
68 changes: 16 additions & 52 deletions test/spec/modules/displayioBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import {spec} from 'modules/displayioBidAdapter.js'
import {BANNER} from '/src/mediaTypes'

describe('Displayio adapter', function () {
const BIDDER = 'displayio'
Expand All @@ -12,10 +12,7 @@ describe('Displayio adapter', function () {
mediaTypes: {
banner: {
sizes: [[320, 480]]
},
video: {
sizes: [[360, 640]]
},
}
},
params: {
siteId: 1,
Expand Down Expand Up @@ -128,53 +125,6 @@ describe('Displayio adapter', function () {
})
})

describe('_getPayload', function () {
const payload = spec._getPayload(bidRequests[0], bidderRequest)
it('should not be empty', function() {
expect(payload).to.not.be.empty
})

it('should have userSession', function() {
expect(payload.userSession).to.be.a('string')
})

it('should have data object', function() {
expect(payload.data).to.be.a('object')
})

it('should have complianceData object', function() {
expect(payload.data.complianceData).to.be.a('object')
})

it('should have device object', function() {
expect(payload.data.device).to.be.a('object')
})

it('should have omidpn', function() {
expect(payload.data.omidpn).to.be.a('string')
})

it('should have integration', function() {
expect(payload.data.integration).to.be.a('string')
})

it('should have bidId', function() {
expect(payload.data.id).to.not.be.empty
})

it('should have action getPlacement', function() {
expect(payload.data.action).to.be.equal('getPlacement')
})

it('should have app parameter', function() {
expect(payload.data.app).to.be.a('number')
})

it('should have placement parameter', function() {
expect(payload.data.placement).to.be.a('number')
})
})

describe('interpretResponse', function () {
const response = {
body: {
Expand All @@ -199,6 +149,8 @@ describe('Displayio adapter', function () {
data: {
data: {
id: 'id_001',
adUnitCode: 'test-div',
renderURL: 'testprebid.com/render.js',
data: {
ref: 'testprebid.com'
}
Expand Down Expand Up @@ -235,5 +187,17 @@ describe('Displayio adapter', function () {
it('should have ad', function() {
expect(ir.ad).to.be.a('string')
})

it('should have mediaType', function() {
expect(ir.mediaType).to.be.equal(BANNER)
})

it('should have adUnitCode', function() {
expect(ir.adUnitCode).to.be.a('string')
})

it('should have renderURL', function() {
expect(ir.renderURL).to.be.a('string')
})
})
})