forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new BidAdapter 'eywamedia' (prebid#4055)
* Adding new BidAdapter 'eywamedia' * removed unused import * removed unused variables * removed unused import * removed unused import - my bad!
- Loading branch information
1 parent
4d94fd1
commit e8a9131
Showing
3 changed files
with
471 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import * as utils from '../src/utils'; | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
|
||
const BIDDER_CODE = 'eywamedia'; | ||
const CURRENCY = 'USD'; | ||
const VERSION = '1.0.0'; | ||
const TIME_TO_LIVE = 360; | ||
const NET_REVENUE = true; | ||
const COOKIE_NAME = 'emaduuid'; | ||
const UUID_LEN = 36; | ||
const SERVER_ENDPOINT = 'https://adtarbostg.eywamedia.com/auctions/prebidjs/3000'; | ||
const localWindow = getTopWindow(); | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: ['banner'], | ||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* @param {object} bid, bid to validate | ||
* @return boolean, true if valid, otherwise false | ||
*/ | ||
isBidRequestValid: function(bid) { | ||
return !!(bid.params.publisherId); | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. | ||
* @return requestPayload Info describing the request to the server. | ||
*/ | ||
buildRequests: function(bidRequests, bidRequest) { | ||
const device = getDeviceInfo(); | ||
const site = getSiteInfo(); | ||
const user = getUserInfo(); | ||
|
||
let requestPayload = { | ||
id: utils.generateUUID(), | ||
publisherId: bidRequests[0].params.publisherId, | ||
device: device, | ||
site: site, | ||
user: user, | ||
bidPayload: bidRequests, | ||
cacheBust: new Date().getTime().toString(), | ||
adapterVersion: VERSION, | ||
tmax: bidRequest.timeout | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: SERVER_ENDPOINT, | ||
options: { | ||
contentType: 'application/json' | ||
}, | ||
data: requestPayload | ||
} | ||
}, | ||
|
||
/** | ||
* Makes Eywamedia Ad Server response compatible to Prebid specs | ||
* @param serverResponse successful response from Ad Server | ||
* @param bidderRequest original bidRequest | ||
* @return {Bid[]} an array of bids | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
var bidObject, response; | ||
var bidRespones = []; | ||
var responses = serverResponse.body; | ||
for (var i = 0; i < responses.length; i++) { | ||
response = responses[i]; | ||
bidObject = { | ||
requestId: response.bidId, | ||
cpm: response.cpm, | ||
width: parseInt(response.width), | ||
height: parseInt(response.height), | ||
creativeId: response.bidId, | ||
currency: CURRENCY, | ||
netRevenue: NET_REVENUE, | ||
ttl: TIME_TO_LIVE, | ||
ad: response.ad, | ||
bidderCode: BIDDER_CODE, | ||
transactionId: response.transactionId, | ||
mediaType: response.respType, | ||
}; | ||
bidRespones.push(bidObject); | ||
} | ||
return bidRespones; | ||
} | ||
} | ||
registerBidder(spec); | ||
|
||
/*************************************** | ||
* Helper Functions | ||
***************************************/ | ||
|
||
/** | ||
* get device type | ||
*/ | ||
function getDeviceType() { | ||
let ua = navigator.userAgent; | ||
// Tablets must be checked before phones. | ||
if ((/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i).test(ua)) { | ||
return 5; // "Tablet" | ||
} | ||
if ((/Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/).test(ua)) { | ||
return 4; // "Phone" | ||
} | ||
return 2; // Personal Computers | ||
}; | ||
|
||
/** | ||
* get device info | ||
*/ | ||
function getDeviceInfo() { | ||
const language = navigator.language; | ||
return { | ||
ua: navigator.userAgent, | ||
language: navigator[language], | ||
devicetype: getDeviceType(), | ||
dnt: utils.getDNT(), | ||
geo: {}, | ||
js: 1 | ||
}; | ||
}; | ||
|
||
/** | ||
* get site info | ||
*/ | ||
function getSiteInfo() { | ||
const topLocation = utils.getTopWindowLocation(); | ||
return { | ||
domain: topLocation.hostname, | ||
page: topLocation.href, | ||
referrer: utils.getTopWindowReferrer(), | ||
desc: getPageDescription(), | ||
title: localWindow.document.title, | ||
}; | ||
}; | ||
|
||
/** | ||
* get user info | ||
*/ | ||
function getUserInfo() { | ||
return { | ||
id: getUserID(), | ||
}; | ||
}; | ||
|
||
/** | ||
* get user Id | ||
*/ | ||
const getUserID = () => { | ||
const i = document.cookie.indexOf(COOKIE_NAME); | ||
|
||
if (i === -1) { | ||
const uuid = utils.generateUUID(); | ||
document.cookie = `${COOKIE_NAME}=${uuid}; path=/`; | ||
return uuid; | ||
} | ||
|
||
const j = i + COOKIE_NAME.length + 1; | ||
return document.cookie.substring(j, j + UUID_LEN); | ||
}; | ||
|
||
/** | ||
* get page description | ||
*/ | ||
function getPageDescription() { | ||
if (document.querySelector('meta[name="description"]')) { | ||
return document.querySelector('meta[name="description"]').getAttribute('content'); // Value of the description metadata from the publisher's page. | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
function getTopWindow() { | ||
try { | ||
return window.top; | ||
} catch (e) { | ||
return window; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Eywamedia Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer: sharath@eywamedia.com | ||
Note: Our ads will only render in mobile and desktop | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Eywamedia Ad Server for bids. | ||
|
||
Eywamedia bid adapter supports Banners. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
// Banner adUnit | ||
{ | ||
code: 'div-gpt-ad-1460505748561-0', | ||
sizes: [[300, 250], [300,600]], | ||
bids: [{ | ||
bidder: 'eywamedia', | ||
params: { | ||
publisherId: 'f63a2362-5aa4-4829-bbd2-2678ced8b63e', //Required - GUID (may include numbers and characters) | ||
bidFloor: 0.50, // optional | ||
cats: ["iab1-1","iab23-2"], // optional | ||
keywords: ["sports", "cricket"], // optional | ||
lat: 12.33333, // optional | ||
lon: 77.32322, // optional | ||
locn: "country$region$city$zip" // optional | ||
} | ||
}] | ||
} | ||
]; | ||
``` |
Oops, something went wrong.