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

Djax Bid Adapter : initial release #12120

Merged
merged 7 commits into from
Aug 17, 2024
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
114 changes: 114 additions & 0 deletions modules/djaxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import * as utils from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import { ajax } from '../src/ajax.js';
import {Renderer} from '../src/Renderer.js';

const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
const BIDDER_CODE = 'djax';
const DOMAIN = 'https://revphpe.djaxbidder.com/header_bidding_vast/';
const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';

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, rendererParams, adUnitCode) {
const renderer = Renderer.install({
id: rendererParams.id,
url: rendererParams.url,
loaded: false,
config: {'player_height': bidAd.height, 'player_width': bidAd.width},
adUnitCode
});
try {
renderer.setRender(outstreamRender);
} catch (err) {
utils.logWarn('Prebid Error calling setRender on renderer', err);
}
return renderer;
}

function sendResponseToServer(data) {
ajax(DOMAIN + 'www/admin/plugins/Prebid/tracking/track.php', null, JSON.stringify(data), {
withCredentials: false,
method: 'POST',
crossOrigin: true
});
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_AD_TYPES,

isBidRequestValid: function(bid) {
return (typeof bid.params !== 'undefined' && parseInt(utils.getValue(bid.params, 'publisherId')) > 0);
},

buildRequests: function(validBidRequests) {
return {
method: 'POST',
url: DOMAIN + 'www/admin/plugins/Prebid/getAd.php',
options: {
withCredentials: false,
crossOrigin: true
},
data: validBidRequests,
};
},

interpretResponse: function(serverResponse, request) {
const response = serverResponse.body;
const bidResponses = [];
var bidRequestResponses = [];

utils._each(response, function(bidAd) {
bidAd.adResponse = {
content: bidAd.vastXml,
height: bidAd.height,
width: bidAd.width
};

bidAd.renderer = bidAd.context === 'outstream' ? createRenderer(bidAd, {
id: bidAd.adUnitCode,
url: RENDERER_URL
}, bidAd.adUnitCode) : undefined;
bidResponses.push(bidAd);
});

bidRequestResponses.push({
function: 'saveResponses',
request: request,
response: bidResponses
});
sendResponseToServer(bidRequestResponses);
return bidResponses;
},

onBidWon: function(bid) {
let wonBids = [];
wonBids.push(bid);
wonBids[0].function = 'onBidWon';
sendResponseToServer(wonBids);
},

onTimeout: function(details) {
details.unshift({ 'function': 'onTimeout' });
sendResponseToServer(details);
}

};

registerBidder(spec);
51 changes: 51 additions & 0 deletions modules/djaxBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Overview

```
Module Name: Djax Bidder Adapter
Module Type: Bidder Adapter
Maintainer: [email protected]
```

# Description

Module that connects to Djax

# Test Parameters
```
var adUnits = [
{
code: 'test-div',
mediaTypes: {
banner: {
sizes: [[300, 250]], // a display size
}
},
bids: [
{
bidder: "djax",
params: {
publisherId: '2' // string - required
}
}
]
}
];
```
var adUnits = [
{
code: 'test-div',
mediaTypes: {
video: {
playerSize: [[480, 320]], // a display size
}
},
bids: [
{
bidder: "djax",
params: {
publisherId: '12' // string - required
}
}
]
}
];
111 changes: 111 additions & 0 deletions test/spec/modules/djaxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { expect } from 'chai';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { spec } from '../../../modules/djaxBidAdapter.js';

const DOMAIN = 'https://revphpe.djaxbidder.com/header_bidding_vast/';
const ENDPOINT = DOMAIN + 'www/admin/plugins/Prebid/getAd.php';

describe('Djax Adapter', function() {
const adapter = newBidder(spec);

describe('inherited functions', function () {
it('should exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});

describe('isBidRequestValidForBanner', () => {
let bid = {
'bidder': 'djax',
'params': {
'publisherId': 2
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'banner': {
'sizes': [
[300, 250]
]
}
},
'sizes': [[300, 250]],
'bidId': '26e88c3c703e66',
'bidderRequestId': '1a8ff729f6c1a3',
'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333',
};

it('should return true when required params found', () => {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', () => {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
wrong: 'missing publisherId'
};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequestsForBanner', () => {
let bidRequests = [
{
'bidder': 'djax',
'params': {
'publisherId': 2
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'banner': {
'sizes': [
[300, 250]
]
}
},
'sizes': [[300, 250]],
'bidId': '26e88c3c703e66',
'bidderRequestId': '1a8ff729f6c1a3',
'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333'
}
];

it('sends bid request to ENDPOINT via POST', () => {
const request = spec.buildRequests(bidRequests);
expect(request.url).to.contain(ENDPOINT);
expect(request.method).to.equal('POST');
});
});

describe('interpretResponseForBanner', () => {
let bidRequests = [
{
'bidder': 'djax',
'params': {
'publisherId': 2
},
'adUnitCode': 'adunit-code',
'mediaTypes': {
'banner': {
'sizes': [
[300, 250]
]
}
},
'sizes': [[300, 250]],
'bidId': '26e88c3c703e66',
'bidderRequestId': '1a8ff729f6c1a3',
'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333'
}
];

it('handles nobid responses', () => {
var request = spec.buildRequests(bidRequests);
let response = '';

let result = spec.interpretResponse(response, request[0]);
expect(result.length).to.equal(0);
});
});

});