-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Advertly: New Bidder Adapter Submission (#4496)
* Add files via upload * Add files via upload * Delete advertlyBidAdapter.js * Delete advertlyBidAdapter.md * Delete advertlyBidAdapter_spec.js * Advertly Adapter * Update advertlyBidAdapter.md * Update advertlyBidAdapter_spec.js * Update advertlyBidAdapter.md * Update advertlyBidAdapter_spec.js * Update advertlyBidAdapter.js * Update advertlyBidAdapter_spec.js * Update advertlyBidAdapter_spec.js * Update advertlyBidAdapter.js * Update Advertly * Advertly Bidder Adapter Files * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Updated with create the new object Updated with create the new object instead of modifying response data * Update with new changes Update with new changes * Update with new changes * update with new changes * Update with new Changes * update advertly * New updates * update advertly * update advertly * update advertly * update advertly * Update advertlyBidAdapter.js * Update advertlyBidAdapter.js * Update advertlyBidAdapter.js * updated advertly * updated advertly * update advertly * update advertly
- Loading branch information
Showing
4 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,127 @@ | ||
import { registerBidder } from '../src/adapters/bidderFactory'; | ||
import { config } from '../src/config'; | ||
import * as utils from '../src/utils'; | ||
import {BANNER, VIDEO} from '../src/mediaTypes'; | ||
import { ajax } from '../src/ajax'; | ||
import {Renderer} from '../src/Renderer'; | ||
|
||
const SUPPORTED_AD_TYPES = [BANNER, VIDEO]; | ||
const BIDDER_CODE = 'advertly'; | ||
const DOMAIN = 'https://api.advertly.com/'; | ||
const RENDERER_URL = '//acdn.adnxs.com/video/outstream/ANOutstreamVideo.js'; | ||
|
||
function isBidRequestValid(bid) { | ||
return (typeof bid.params !== 'undefined' && parseInt(utils.getValue(bid.params, 'publisherId')) > 0); | ||
} | ||
|
||
function buildRequests(validBidRequests) { | ||
return { | ||
method: 'POST', | ||
url: DOMAIN + 'www/admin/plugins/Prebid/getAd.php', | ||
options: { | ||
withCredentials: false, | ||
crossOrigin: true | ||
}, | ||
data: validBidRequests, | ||
}; | ||
} | ||
|
||
function interpretResponse(serverResponse, request) { | ||
const response = serverResponse.body; | ||
const bidResponses = []; | ||
var bidRequestResponses = []; | ||
utils._each(response, function(bidAd) { | ||
let bnd = {}; | ||
Object.assign(bnd, bidAd); | ||
bnd.adResponse = { | ||
content: bidAd.vastXml, | ||
height: bidAd.height, | ||
width: bidAd.width | ||
}; | ||
bnd.ttl = config.getConfig('_bidderTimeout') | ||
bnd.renderer = bidAd.context === 'outstream' ? createRenderer(bidAd, RENDERER_URL) : undefined; | ||
bidResponses.push(bnd); | ||
}); | ||
|
||
bidRequestResponses.push({ | ||
function: 'saveResponses', | ||
request: request, | ||
response: bidResponses | ||
}); | ||
sendResponseToServer(bidRequestResponses); | ||
return bidResponses; | ||
} | ||
|
||
function outstreamRender(bidAd) { | ||
bidAd.renderer.push(() => { | ||
window.ANOutstreamVideo.renderAd({ | ||
sizes: [bidAd.width, bidAd.height], | ||
width: bidAd.width, | ||
height: bidAd.height, | ||
targetId: bidAd.adUnitCode, | ||
adResponse: bidAd.adResponse, | ||
rendererOptions: { | ||
showVolume: false, | ||
allowFullscreen: false | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function createRenderer(bidAd, url) { | ||
const renderer = Renderer.install({ | ||
id: bidAd.adUnitCode, | ||
url: url, | ||
loaded: false, | ||
config: {'player_height': bidAd.height, 'player_width': bidAd.width}, | ||
adUnitCode: bidAd.adUnitCode | ||
}); | ||
try { | ||
renderer.setRender(outstreamRender); | ||
} catch (err) { | ||
utils.logWarn('Prebid Error calling setRender on renderer', err); | ||
} | ||
return renderer; | ||
} | ||
|
||
function onBidWon(bid) { | ||
let wonBids = []; | ||
wonBids.push(bid); | ||
wonBids[0].function = 'onBidWon'; | ||
sendResponseToServer(wonBids); | ||
} | ||
|
||
function onTimeout(details) { | ||
details.unshift({ 'function': 'onTimeout' }); | ||
sendResponseToServer(details); | ||
} | ||
|
||
function sendResponseToServer(data) { | ||
ajax(DOMAIN + 'www/admin/plugins/Prebid/tracking/track.php', null, JSON.stringify(data), { | ||
withCredentials: false, | ||
method: 'POST', | ||
crossOrigin: true | ||
}); | ||
} | ||
|
||
function getUserSyncs(syncOptions) { | ||
if (syncOptions.iframeEnabled) { | ||
return [{ | ||
type: 'iframe', | ||
url: DOMAIN + 'www/admin/plugins/Prebid/userSync.php' | ||
}]; | ||
} | ||
} | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
supportedMediaTypes: SUPPORTED_AD_TYPES, | ||
isBidRequestValid, | ||
buildRequests, | ||
interpretResponse, | ||
getUserSyncs, | ||
onBidWon, | ||
onTimeout | ||
}; | ||
|
||
registerBidder(spec); |
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,50 @@ | ||
# Overview | ||
|
||
``` | ||
Module Name: Advertly Bid Adapter | ||
Module Type: Bidder Adapter | ||
Maintainer : [email protected] | ||
``` | ||
|
||
# Description | ||
|
||
Connects to Advertly Ad Server for bids. | ||
|
||
advertly bid adapter supports Banner and Video. | ||
|
||
# Test Parameters | ||
``` | ||
var adUnits = [ | ||
//bannner object | ||
{ | ||
code: 'banner-ad-slot', | ||
mediaTypes: { | ||
banner: { | ||
sizes: [[300, 250], [300,600]], | ||
} | ||
}, | ||
bids: [{ | ||
bidder: 'advertly', | ||
params: { | ||
publisherId: 2 | ||
} | ||
}] | ||
}, | ||
//video object | ||
{ | ||
code: 'video-ad-slot', | ||
mediaTypes: { | ||
video: { | ||
context: 'instream', | ||
playerSize: [640, 480], | ||
}, | ||
}, | ||
bids: [{ | ||
bidder: "advertly", | ||
params: { | ||
publisherId: 2 | ||
} | ||
}] | ||
}]; | ||
``` |
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,159 @@ | ||
import { expect } from 'chai'; | ||
import { spec } from 'modules/advertlyBidAdapter'; | ||
|
||
const ENDPOINT = 'https://api.advertly.com/www/admin/plugins/Prebid/getAd.php'; | ||
|
||
describe('The Advertly bidding adapter', function () { | ||
describe('isBidRequestValid', function () { | ||
it('should return false when given an invalid bid', function () { | ||
const bid = { | ||
bidder: 'advertly', | ||
}; | ||
const isValid = spec.isBidRequestValid(bid); | ||
expect(isValid).to.equal(false); | ||
}); | ||
|
||
it('should return true when given a publisherId in bid', function () { | ||
const bid = { | ||
bidder: 'advertly', | ||
params: { | ||
publisherId: 2 | ||
}, | ||
}; | ||
const isValid = spec.isBidRequestValid(bid); | ||
expect(isValid).to.equal(true); | ||
}); | ||
}); | ||
|
||
describe('buildRequests', function () { | ||
const bidRequests = [{ | ||
'bidder': 'advertly', | ||
'params': { | ||
'publisherId': 2 | ||
}, | ||
'adUnitCode': 'adunit-code', | ||
'sizes': [ | ||
[300, 250], | ||
[300, 600] | ||
] | ||
}]; | ||
|
||
const request = spec.buildRequests(bidRequests); | ||
|
||
it('sends bid request to our endpoint via POST', function () { | ||
expect(request.method).to.equal('POST'); | ||
}); | ||
|
||
it('check endpoint url', function () { | ||
expect(request.url).to.equal(ENDPOINT) | ||
}); | ||
|
||
it('sets the proper banner object', function () { | ||
expect(bidRequests[0].params.publisherId).to.equal(2); | ||
}) | ||
}); | ||
const response = { | ||
body: [ | ||
{ | ||
'requestId': '2ee937f15015c6', | ||
'cpm': '0.2000', | ||
'width': 300, | ||
'height': 600, | ||
'creativeId': '4', | ||
'currency': 'USD', | ||
'netRevenue': true, | ||
'ad': 'ads.html', | ||
'mediaType': 'banner' | ||
}, | ||
{ | ||
'requestId': '3e1af92622bdc', | ||
'cpm': '0.2000', | ||
'creativeId': '4', | ||
'context': 'outstream', | ||
'currency': 'USD', | ||
'netRevenue': true, | ||
'vastUrl': 'tezt.xml', | ||
'width': 640, | ||
'height': 480, | ||
'mediaType': 'video' | ||
}] | ||
}; | ||
|
||
const request = [ | ||
{ | ||
'bidder': 'advertly', | ||
'params': { | ||
'publisherId': 2 | ||
}, | ||
'mediaTypes': { | ||
'banner': { | ||
'sizes': [ | ||
[300, 600] | ||
] | ||
} | ||
}, | ||
'bidId': '2ee937f15015c6', | ||
'src': 'client', | ||
}, | ||
{ | ||
'bidder': 'advertly', | ||
'params': { | ||
'publisherId': 2 | ||
}, | ||
'mediaTypes': { | ||
'video': { | ||
'context': 'outstream', | ||
'playerSize': [ | ||
[640, 480] | ||
] | ||
} | ||
}, | ||
'bidId': '3e1af92622bdc', | ||
'src': 'client', | ||
} | ||
]; | ||
|
||
describe('interpretResponse', function () { | ||
it('return empty array when no ad found', function () { | ||
const response = {}; | ||
const request = { bidRequests: [] }; | ||
const bids = spec.interpretResponse(response, request); | ||
expect(bids).to.have.lengthOf(0); | ||
}); | ||
|
||
it('check response for banner and video', function () { | ||
const bids = spec.interpretResponse(response, request); | ||
expect(bids).to.have.lengthOf(2); | ||
expect(bids[0].requestId).to.equal('2ee937f15015c6'); | ||
expect(bids[0].cpm).to.equal('0.2000'); | ||
expect(bids[1].cpm).to.equal('0.2000'); | ||
expect(bids[0].width).to.equal(300); | ||
expect(bids[0].height).to.equal(600); | ||
expect(bids[1].vastUrl).to.not.equal(''); | ||
expect(bids[0].ad).to.not.equal(''); | ||
expect(bids[1].adResponse).to.not.equal(''); | ||
expect(bids[1].renderer).not.to.be.an('undefined'); | ||
}); | ||
}); | ||
|
||
describe('On winning bid', function () { | ||
const bids = spec.interpretResponse(response, request); | ||
spec.onBidWon(bids); | ||
}); | ||
|
||
describe('On bid Time out', function () { | ||
const bids = spec.interpretResponse(response, request); | ||
spec.onTimeout(bids); | ||
}); | ||
|
||
describe('user sync', function () { | ||
it('to check the user sync iframe', function () { | ||
let syncs = spec.getUserSyncs({ | ||
iframeEnabled: true | ||
}); | ||
expect(syncs).to.not.be.an('undefined'); | ||
expect(syncs).to.have.lengthOf(1); | ||
expect(syncs[0].type).to.equal('iframe'); | ||
}); | ||
}); | ||
}); |