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

Update for Media.net adapter #2232

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
77 changes: 74 additions & 3 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,68 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import events from 'src/events';
import CONSTANTS from 'src/constants.json';
import { config } from 'src/config';
import * as url from 'src/url';

const BIDDER_CODE = 'medianet';
const BID_URL = 'https://prebid.media.net/rtb/prebid';
const EVENT_PIXEL_URL = 'lg1.media.net/log';
const { BID_TIMEOUT } = CONSTANTS.EVENTS;
const TIMEOUT_EVENT_NAME = 'client_timeout';

let bidParams = {};

events.on(BID_TIMEOUT, function (timedOutBidders) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Listening to and logging event data isn't allowed in a bidder adapter, but is in an analytics adapter.

Choose a reason for hiding this comment

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

Hey @matthewlane ,

Shouldn't the bidder timeout be allowed in the main adapter, the analytics adapter could listen to a lot more events based on the environment. The publisher might not always pick the analytics adapter, as it generally leads to more px calls on the browser.

However the client timeout is an important event that the bidder must listen to to optimize, tweak things at its end. This optimization could directly lead to better yields to the publisher.

Your views?

Thanks,
Ruturaj

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense. The BID_TIMEOUT event still shouldn't be listened to in bidder adapters as it may contain data from other bidders, even though you are filtering them out below, but I've create an issue to define and implement a way for bidders to subscribe to their own timed out event data: #2254. Feel free to comment on that or use it for tracking and whenever a PR is merged you'll be able to use it here

let mnetBidder = timedOutBidders.filter(bidder => bidder.bidder === BIDDER_CODE);
if (mnetBidder.length > 0) {
let eventData = {
name: TIMEOUT_EVENT_NAME,
value: config.getConfig('bidderTimeout')
};
logEvent(eventData).trigger(mnetBidder);
}
});

function logEvent (event) {
function generateUrl(data) {
let getParams = {
protocol: 'https',
hostname: EVENT_PIXEL_URL,
search: getLoggingData(data)
};

return url.format(getParams);
}

function getLoggingData(data) {
data = data || [];

let params = {};
params.logid = 'kfk';
params.evtid = 'projectevents';
params.project = 'prebid';
params.acid = (data[0] && data[0].auctionId) ? data[0].auctionId : '';
params.cid = bidParams.cid || '';
params.crid = data.map((adunit) => adunit.adUnitCode).toString();
params.crid_count = data.length || 0;
params.dn = utils.getTopWindowLocation().host || '';
params.requrl = utils.getTopWindowUrl() || '';
params.event = event.name;
params.value = event.value || '';
params.pbver = $$PREBID_GLOBAL$$.version;

return params;
}

function trigger(data) {
utils.triggerPixel(generateUrl(data));
}

return {
trigger: trigger
}
}

function siteDetails(site) {
site = site || {};
Expand Down Expand Up @@ -35,7 +95,8 @@ function getSize(size) {

function configuredParams(params) {
return {
customer_id: params.cid
customer_id: params.cid,
prebid_version: $$PREBID_GLOBAL$$.version
}
}

Expand All @@ -46,7 +107,8 @@ function slotParams(bidRequest) {
ext: {
dfp_id: bidRequest.adUnitCode
},
banner: transformSizes(bidRequest.sizes)
banner: transformSizes(bidRequest.sizes),
all: bidRequest.params
};

if (bidRequest.params.crid) {
Expand All @@ -61,11 +123,13 @@ function slotParams(bidRequest) {
}

function generatePayload(bidRequests) {
bidParams = bidRequests[0].params;
return {
site: siteDetails(bidRequests[0].params.site),
ext: configuredParams(bidRequests[0].params),
id: bidRequests[0].auctionId,
imp: bidRequests.map(request => slotParams(request))
imp: bidRequests.map(request => slotParams(request)),
tmax: config.getConfig('bidderTimeout')
}
}

Expand Down Expand Up @@ -136,6 +200,13 @@ export const spec = {
return validBids;
}

if (serverResponse.body.ext && serverResponse.body.ext.nbr) {
let eventData = {
name: serverResponse.body.ext.nbr,
};
logEvent(eventData).trigger();
}

let bids = serverResponse.body.bidList;
if (!utils.isArray(bids) || bids.length === 0) {
utils.logInfo(`${BIDDER_CODE} : no bids`);
Expand Down
78 changes: 73 additions & 5 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {expect} from 'chai';
import {spec} from 'modules/medianetBidAdapter';
import { config } from 'src/config';

let VALID_BID_REQUEST = [{
'bidder': 'medianet',
Expand Down Expand Up @@ -68,14 +69,64 @@ let VALID_BID_REQUEST = [{
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d'
}],
VALID_PAYLOAD_INVALID_BIDFLOOR = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
},
'ext': {
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
'id': '28f8f8130a583e',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-0'
},
'banner': [{
'w': 300,
'h': 250
}],
'all': {
'cid': 'customer_id',
'bidfloor': 'abcdef',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}, {
'id': '3f97ca71b1e5c2',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-123'
},
'banner': [{
'w': 300,
'h': 251
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
},
'ext': {
'customer_id': 'customer_id'
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
Expand All @@ -86,7 +137,15 @@ let VALID_BID_REQUEST = [{
'banner': [{
'w': 300,
'h': 250
}]
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}, {
'id': '3f97ca71b1e5c2',
'ext': {
Expand All @@ -95,8 +154,17 @@ let VALID_BID_REQUEST = [{
'banner': [{
'w': 300,
'h': 251
}]
}]
}],
'all': {
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest'
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PARAMS = {
bidder: 'medianet',
Expand Down Expand Up @@ -286,7 +354,7 @@ describe('Media.net bid adapter', () => {

it('should ignore bidfloor if not a valid number', () => {
let bidReq = spec.buildRequests(VALID_BID_REQUEST_INVALID_BIDFLOOR);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_INVALID_BIDFLOOR);
});
});

Expand Down