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

Enforce video branch #3478

Merged
merged 10 commits into from
Jan 31, 2019
136 changes: 83 additions & 53 deletions modules/gamoshiBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { config } from '../src/config';
import { Renderer } from '../src/Renderer';
import {registerBidder} from '../src/adapters/bidderFactory';
import {config} from '../src/config';
import {Renderer} from '../src/Renderer';
import {BANNER, VIDEO} from "../src/mediaTypes";

const ENDPOINTS = {
'cleanmedia': 'https://bidder.cleanmediaads.com',
'gamoshi': 'https://rtb.gamoshi.io',
'gambid': 'https://rtb.gamoshi.io',
};

export const helper = {

getTopFrame: function () {
try {
return window.top === window ? 1 : 0;
} catch (e) {
}
return 0;
},

startsWith: function (str, search) {
return str.substr(0, search.length) === search;
},

getTopWindowDomain: function (url) {
const domainStart = url.indexOf('://') + '://'.length;
return url.substring(domainStart, url.indexOf('/', domainStart) < 0 ? url.length : url.indexOf('/', domainStart));
},

getTopWindowReferer: function () {
try {
return window.top.document.referrer;
} catch (e) {
utils.logMessage('Failed obtaining top window\'s referrer: ', e);
try {
return window.document.referrer;
} catch (e) {
utils.logMessage('Failed obtaining current window\'s referrer: ', e);
getMediaType: function (bid) {
if (bid.ext) {
if (bid.ext.media_type) {
return bid.ext.media_type.toLowerCase();
} else if (bid.ext.vast_url) {
return VIDEO;
} else {
return BANNER;
}
}
return '';
return BANNER;
}
}
};

export const spec = {
code: 'gamoshi',
aliases: ['gambid', 'cleanmedia'],
supportedMediaTypes: ['banner', 'video'],

isBidRequestValid: function (bid) {
return !!bid.params.supplyPartnerId && typeof bid.params.supplyPartnerId === 'string' &&
return !!bid.params.supplyPartnerId &&
typeof bid.params.supplyPartnerId === 'string' &&
(typeof bid.params['rtbEndpoint'] === 'undefined' || typeof bid.params['rtbEndpoint'] === 'string') &&
(typeof bid.params.bidfloor === 'undefined' || typeof bid.params.bidfloor === 'number') &&
(typeof bid.params['adpos'] === 'undefined' || typeof bid.params['adpos'] === 'number') &&
Expand All @@ -54,25 +58,25 @@ export const spec = {
buildRequests: function (validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const {adUnitCode, auctionId, mediaTypes, params, sizes, transactionId} = bidRequest;
const baseEndpoint = params['rtbEndpoint'] || 'https://rtb.gamoshi.io';
const baseEndpoint = params['rtbEndpoint'] || ENDPOINTS[bidRequest.bidder] || ENDPOINTS['gamoshi'];
const rtbEndpoint = `${baseEndpoint}/r/${params.supplyPartnerId}/bidr?rformat=open_rtb&reqformat=rtb_json&bidder=prebid` + (params.query ? '&' + params.query : '');
let referer = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
let url = config.getConfig('pageUrl') || referer || utils.getTopWindowUrl();
let url = config.getConfig('pageUrl') || bidderRequest.refererInfo.referer;

const rtbBidRequest = {
'id': auctionId,
'site': {
'domain': helper.getTopWindowDomain(url),
'page': url,
'ref': helper.getTopWindowReferer()
'ref': bidderRequest.refererInfo.referer
},
'device': {
'ua': navigator.userAgent
},
'imp': [],
'ext': {}
};
if (bidderRequest && bidderRequest.gdprConsent) {

if (bidderRequest.gdprConsent) {
Copy link
Collaborator

@robertrmartinez robertrmartinez Jan 31, 2019

Choose a reason for hiding this comment

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

@sa1omon

If a pub enables the consent module, but for some reason the consent information cannot be found,
then prebid passes an object like so to the bidders:

{
   gdprConsent: {
      consentString: undefined
      gdprApplies: undefined
      vendorData: undefined
  }
}

which in this scenario would end up sending an empty object to your exchange like so

{
   ... 
   ext: {
      gdpConsent: {}
   }
}

Looks like your ad server handles it just fine but wanted to make it known!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the insight, we will update the code in the next PR.

rtbBidRequest.ext.gdpr_consent = {
consent_string: bidderRequest.gdprConsent.consentString,
consent_required: bidderRequest.gdprConsent.gdprApplies
Expand All @@ -88,25 +92,44 @@ export const spec = {
'secure': helper.startsWith(utils.getTopWindowUrl().toLowerCase(), 'http://') ? 0 : 1
};

if (!mediaTypes || mediaTypes.banner) {
imp.banner = {
w: sizes.length ? sizes[0][0] : 300,
h: sizes.length ? sizes[0][1] : 250,
pos: params.pos || 0,
topframe: helper.getTopFrame()
};
} else if (mediaTypes.video) {
imp.video = {
w: sizes.length ? sizes[0][0] : 300,
h: sizes.length ? sizes[0][1] : 250,
protocols: params.protocols || [1, 2, 3, 4, 5, 6],
pos: params.pos || 0,
topframe: helper.getTopFrame()
};
} else {
const hasFavoredMediaType =
params.favoredMediaType && this.supportedMediaTypes.includes(params.favoredMediaType);

if ((!mediaTypes || mediaTypes.banner)) {
if (!hasFavoredMediaType || params.favoredMediaType === 'banner') {
const bannerImp = Object.assign({}, imp, {
banner: {
w: sizes.length ? sizes[0][0] : 300,
h: sizes.length ? sizes[0][1] : 250,
pos: params.pos || 0,
topframe: helper.getTopFrame()
}
});
rtbBidRequest.imp.push(bannerImp);
}
}

if (mediaTypes && mediaTypes.video) {
if (!hasFavoredMediaType || params.favoredMediaType === 'video') {
const videoImp = Object.assign({}, imp, {
video: {
w: sizes.length ? sizes[0][0] : 300,
h: sizes.length ? sizes[0][1] : 250,
protocols: params.protocols || [1, 2, 3, 4, 5, 6],
pos: params.pos || 0,
ext: {
context: mediaTypes.video.context
}
}
});
rtbBidRequest.imp.push(videoImp);
}
}

if (rtbBidRequest.imp.length === 0) {
return;
}
rtbBidRequest.imp.push(imp);

return {method: 'POST', url: rtbEndpoint, data: rtbBidRequest, bidRequest};
});
},
Expand All @@ -119,28 +142,35 @@ export const spec = {
}

const bids = response.seatbid.reduce((acc, seatBid) => acc.concat(seatBid.bid), []);
const outBids = [];
let outBids = [];

bids.forEach(bid => {
const outBid = {
adId: bidRequest.bidRequest.adUnitCode,
requestId: bidRequest.bidRequest.bidId,
cpm: bid.price,
width: bid.w,
height: bid.h,
ttl: 60 * 10,
creativeId: bid.crid,
netRevenue: true,
currency: bid.cur || response.cur
currency: bid.cur || response.cur,
adUnitCode: bidRequest.bidRequest.adUnitCode,
mediaType: helper.getMediaType(bid)

};
if (!bidRequest.bidRequest.mediaTypes || bidRequest.bidRequest.mediaTypes.banner) {
outBids.push(Object.assign({}, outBid, {mediaType: 'banner', ad: bid.adm}));
} else if (bidRequest.bidRequest.mediaTypes.video) {
const context = utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.video.context');
outBids.push(Object.assign({}, outBid, {
mediaType: 'video',
vastUrl: bid.ext.vast_url,
vastXml: bid.adm,
renderer: context === 'outstream' ? newRenderer(bidRequest.bidRequest, bid) : undefined
}));

if (utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.' + outBid.mediaType)) {
if (outBid.mediaType === BANNER) {
outBids.push(Object.assign({}, outBid, {ad: bid.adm}));
} else if (outBid.mediaType === VIDEO) {
const context = utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.video.context');
outBids.push(Object.assign({}, outBid, {
vastUrl: bid.ext.vast_url,
vastXml: bid.adm,
renderer: context === 'outstream' ? newRenderer(bidRequest.bidRequest, bid) : undefined
}));
}
}
});
return outBids;
Expand Down Expand Up @@ -181,7 +211,7 @@ export const spec = {

function newRenderer(bidRequest, bid, rendererOptions = {}) {
const renderer = Renderer.install({
url: (bidRequest.params && bidRequest.params.rendererUrl) || (bid.ext && bid.ext.renderer_url) || '//s.gamoshi.io/video/latest/renderer.js',
url: (bidRequest.params && bidRequest.params.rendererUrl) || (bid.ext && bid.ext.renderer_url) || '//s.wlplayer.com/video/latest/renderer.js',
config: rendererOptions,
loaded: false,
});
Expand Down
46 changes: 43 additions & 3 deletions modules/gamoshiBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
Module Name: Gamoshi Bid Adapter
Module Type: Bidder Adapter
Maintainer: moses@gamoshi.com
Maintainer: salomon@gamoshi.com
```

# Description
Expand Down Expand Up @@ -47,7 +47,6 @@ var adUnits = [
// Video outstream adUnit
{
code: 'video-outstream',
sizes: [[300, 250]],
mediaTypes: {
video: {
context: 'outstream',
Expand Down Expand Up @@ -76,6 +75,47 @@ var adUnits = [
//instl: 0
}
}]
}
},

// Multi-Format adUnit
{
code: 'banner-div',
mediaTypes: {
video: {
context: 'outstream',
playerSize: [300, 250]
},
banner: {
sizes: [[300, 250]]
}
},
bids: [{
bidder: 'gamoshi',
params: {

// ID of the supply partner you created in the Gamoshi dashboard
supplyPartnerId: '1253',

// OPTIONAL: if you have a whitelabel account on Gamoshi, specify it here
//rtbEndpoint: 'https://my.custom-whitelabel-domain.io',

// OPTIONAL: custom bid floor
bidfloor: 0.01,

// OPTIONAL: if you know the ad position on the page, specify it here
// (this corresponds to "Ad Position" in OpenRTB 2.3, section 5.4)
//adpos: 1,

// OPTIONAL: whether this is an interstitial placement (0 or 1)
// (see "instl" property in "Imp" object in the OpenRTB 2.3, section 3.2.2)
//instl: 0,

// OPTIONAL: enable enforcement bids of a specific media type (video, banner)
// in this ad placement
// query: 'key1=value1&k2=value2',
// favoredMediaType: 'video',
}
}]
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the expanded markdown information!

];
```
Loading