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 ucfunnelBidAdapter #1990

Merged
merged 19 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
93 changes: 93 additions & 0 deletions modules/ucfunnelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';

const VER = 'ADGENT_PREBID-2017122101';
const BID_REQUEST_BASE_URL = 'https://hb.aralego.com/header';
const UCFUNNEL_BIDDER_CODE = 'ucfunnel';

export const spec = {
code: UCFUNNEL_BIDDER_CODE,
supportedMediaTypes: [BANNER],
/**
* Check if the bid is a valid zone ID in either number or string form
* @param {object} bid the ucfunnel bid to validate
* @return boolean for whether or not a bid is valid
*/
isBidRequestValid: function(bid) {
return !!(bid && bid.params && bid.params.adid);
},

/**
* Format the bid request object for our endpoint
* @param {BidRequest[]} bidRequests Array of ucfunnel bidders
* @return object of parameters for Prebid AJAX request
*/
buildRequests: function(bidReqs) {
var bidRequests = [];
utils._each(bidReqs, function (bid) {
var ucfunnelUrlParams = buildUrlParams(bid);
bidRequests.push({
method: 'GET',
url: BID_REQUEST_BASE_URL,
data: ucfunnelUrlParams,
bidRequest: bid
});
});

return bidRequests;
},

/**
* Format ucfunnel responses as Prebid bid responses
* @param {ucfunnelResponseObj} ucfunnelResponse A successful response from ucfunnel.
* @return {Bid[]} An array of formatted bids.
*/
interpretResponse: function (ucfunnelResponseObj, request) {
var bidResponses = [];
var bidRequest = request.bidRequest;
var responseBody = ucfunnelResponseObj ? ucfunnelResponseObj.body : {};

bidResponses.push({
requestId: bidRequest.bidId,
cpm: responseBody.cpm || 0,
width: responseBody.width,
height: responseBody.height,
creativeId: responseBody.ad_id,
dealId: responseBody.deal || null,
currency: 'USD',
netRevenue: true,
ttl: 1000,
mediaType: BANNER,
ad: responseBody.adm
});

return bidResponses;
}
};
registerBidder(spec);

function buildUrlParams(bid) {
const host = utils.getTopWindowLocation().host;
const page = utils.getTopWindowLocation().pathname;
const refer = document.referrer;
const language = navigator.language;
const dnt = (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0;

let queryString = [
'ifr', '0',
'bl', language,
'je', '1',
'dnt', dnt,
'host', host,
'u', page,
'ru', refer,
'adid', utils.getBidIdParameter('adid', bid.params),
'ver', VER
];

return queryString.reduce(
(memo, curr, index) =>
index % 2 === 0 && queryString[index + 1] !== undefined ? memo + curr + '=' + encodeURIComponent(queryString[index + 1]) + '&' : memo, ''
).slice(0, -1);
}
30 changes: 30 additions & 0 deletions modules/ucfunnelBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Overview

```
Module Name: ucfunnel Bid Adapter
Module Type: Bidder Adapter
Maintainer: ryan.chou@ucfunnel.com
```

# Description

This module connects to ucfunnel's demand sources. It supports display, and rich media formats.
ucfunnel will provide ``adid`` that are specific to your ad type.
Please reach out to ``pr@ucfunnel.com`` to set up an ucfunnel account and above ids.
Use bidder code ```ucfunnel``` for all ucfunnel traffic.

# Test Parameters

```
var adUnits = [
{
code: 'test-LERC',
sizes: [[300, 250]],
bids: [{
bidder: 'ucfunnel',
params: {
adid: "test-ad-83444226E44368D1E32E49EEBE6D29" //String - required
}
}
];
```