Skip to content

Commit

Permalink
Marsmedia & videofy adapters - Add onTimeout & onSetTargeting (#5352)
Browse files Browse the repository at this point in the history
* Change publisherId to zoneId
Add gdpr
Add supply chain
Add video media type

* Remove comments

* Fix unit test coverage

* fix request id bug
add vastXml to video response

* Remove bid response default sizes

* Change endpoint url

* Add unit test for vastXml

* Change end point

* Remove trailing-space

* Add onBidWon function

* New adapter - videofy

* Marsmedia & Videofy - Add onTimeout onSetTargeting

* Create sendbeacon function
  • Loading branch information
vladi-mmg authored Jun 17, 2020
1 parent 4ec4591 commit eb4bc85
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 4 deletions.
18 changes: 15 additions & 3 deletions modules/marsmediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,30 @@ function MarsmediaAdapter() {
};

this.onBidWon = function (bid) {
const cpm = bid.pbMg;
if (typeof bid.nurl !== 'undefined') {
const cpm = bid.pbMg;
bid.nurl = bid.nurl.replace(
/\$\{AUCTION_PRICE\}/,
cpm
);
utils.triggerPixel(bid.nurl, null);
};
sendbeacon(bid, 17)
};

this.onTimeout = function (bid) {
sendbeacon(bid, 19)
};

this.onSetTargeting = function (bid) {
sendbeacon(bid, 20)
};

function sendbeacon(bid, type) {
const bidString = JSON.stringify(bid);
const encodedBuf = window.btoa(bidString);
utils.triggerPixel('https://ping-hqx-1.go2speed.media/notification/rtb/beacon/?bt=17&hb_j=' + encodedBuf, null);
};
utils.triggerPixel('https://ping-hqx-1.go2speed.media/notification/rtb/beacon/?bt=' + type + '&bid=3mhdom&hb_j=' + encodedBuf, null);
}

this.interpretResponse = function (serverResponse) {
let responses = serverResponse.body || [];
Expand Down
40 changes: 39 additions & 1 deletion modules/videofyBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { Renderer } from '../src/Renderer.js';
import * as utils from '../src/utils.js';

const BIDDER_CODE = 'videofy';
const TTL = 600;
Expand Down Expand Up @@ -250,13 +251,50 @@ function getUserSyncs(syncOptions, serverResponses) {
}
}

function onBidWon(bid) {
sendbeacon(bid, 17);
}

function onTimeout(bid) {
sendbeacon(bid, 19);
}

function onSetTargeting(bid) {
sendbeacon(bid, 20);
}

function sendbeacon(bid, type) {
const bidCopy = {
bidder: bid.bidder,
cpm: bid.cpm,
originalCpm: bid.originalCpm,
currency: bid.currency,
originalCurrency: bid.originalCurrency,
timeToRespond: bid.timeToRespond,
statusMessage: bid.statusMessage,
width: bid.width,
height: bid.height,
size: bid.size,
params: bid.params,
status: bid.status,
adserverTargeting: bid.adserverTargeting,
ttl: bid.ttl
};
const bidString = JSON.stringify(bidCopy);
const encodedBuf = window.btoa(bidString);
utils.triggerPixel('https://beacon.videofy.io/notification/rtb/beacon/?bt=' + type + '&bid=hcwqso&hb_j=' + encodedBuf, null);
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [VIDEO],
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs
getUserSyncs,
onBidWon,
onTimeout,
onSetTargeting
};

registerBidder(spec);
34 changes: 34 additions & 0 deletions test/spec/modules/marsmediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,38 @@ describe('marsmedia adapter tests', function () {
expect(utils.triggerPixel.called).to.equal(true);
});
});

describe('on Timeout', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onTimeout).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onTimeout({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});

describe('on Set Targeting', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onSetTargeting).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onSetTargeting({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});
});
53 changes: 53 additions & 0 deletions test/spec/modules/videofyBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { spec } from 'modules/videofyBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import * as utils from '../../../src/utils.js';

const { expect } = require('chai');

describe('Videofy Bid Adapter Test', function () {
Expand Down Expand Up @@ -197,4 +199,55 @@ describe('Videofy Bid Adapter Test', function () {
expect(pixel.type).to.equal('iframe');
});
});

describe('on bidWon', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onBidWon).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onBidWon({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});

describe('on Timeout', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onTimeout).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onTimeout({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});

describe('on Set Targeting', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onSetTargeting).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onSetTargeting({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});
});

0 comments on commit eb4bc85

Please sign in to comment.