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

Vidazoo Bid Adapter: Implement onBidWon #11057

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 45 additions & 2 deletions modules/vidazooBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import {_each, deepAccess, isFn, parseSizesInput, parseUrl, uniques, isArray} from '../src/utils.js';
import {
_each,
deepAccess,
isFn,
parseSizesInput,
parseUrl,
uniques,
isArray,
formatQS,
triggerPixel
} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getStorageManager} from '../src/storageManager.js';
Expand Down Expand Up @@ -271,6 +281,7 @@ function interpretResponse(serverResponse, request) {
height,
currency,
bidId,
nurl,
advertiserDomains,
metaData,
mediaType = BANNER
Expand All @@ -290,6 +301,10 @@ function interpretResponse(serverResponse, request) {
ttl: exp || TTL_SECONDS,
};

if (nurl) {
response.nurl = nurl;
}

if (metaData) {
Object.assign(response, {
meta: metaData
Expand Down Expand Up @@ -350,6 +365,33 @@ function getUserSyncs(syncOptions, responses, gdprConsent = {}, uspConsent = '',
return syncs;
}

/**
* @param {Bid} bid
*/
function onBidWon(bid) {
if (!bid.nurl) {
return;
}
const wonBid = {
adId: bid.adId,
creativeId: bid.creativeId,
auctionId: bid.auctionId,
transactionId: bid.transactionId,
adUnitCode: bid.adUnitCode,
cpm: bid.cpm,
currency: bid.currency,
originalCpm: bid.originalCpm,
originalCurrency: bid.originalCurrency,
netRevenue: bid.netRevenue,
mediaType: bid.mediaType,
timeToRespond: bid.timeToRespond,
status: bid.status,
};
const qs = formatQS(wonBid);
const url = bid.nurl + (bid.nurl.indexOf('?') === -1 ? '?' : '&') + qs;
triggerPixel(url);
}

export function hashCode(s, prefix = '_') {
const l = s.length;
let h = 0
Expand Down Expand Up @@ -445,7 +487,8 @@ export const spec = {
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs
getUserSyncs,
onBidWon
};

registerBidder(spec);
70 changes: 70 additions & 0 deletions test/spec/modules/vidazooBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,14 @@ describe('VidazooBidAdapter', function () {
expect(responses).to.have.length(1);
expect(responses[0].ttl).to.equal(300);
});

it('should add nurl if exists on response', function () {
const serverResponse = utils.deepClone(SERVER_RESPONSE);
serverResponse.body.results[0].nurl = 'https://test.com/win-notice?test=123';
const responses = adapter.interpretResponse(serverResponse, REQUEST);
expect(responses).to.have.length(1);
expect(responses[0].nurl).to.equal('https://test.com/win-notice?test=123');
});
});

describe('user id system', function () {
Expand Down Expand Up @@ -833,4 +841,66 @@ describe('VidazooBidAdapter', function () {
expect(parsed).to.be.equal(value);
});
});

describe('validate onBidWon', function () {
beforeEach(function () {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function () {
utils.triggerPixel.restore();
});

it('should call triggerPixel if nurl exists', function () {
const bid = {
adUnitCode: 'div-gpt-ad-12345-0',
adId: '2d52001cabd527',
auctionId: '1fdb5ff1b6eaa7',
transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf',
status: 'rendered',
timeToRespond: 100,
cpm: 0.8,
originalCpm: 0.8,
creativeId: '12610997325162499419',
currency: 'USD',
originalCurrency: 'USD',
height: 250,
mediaType: 'banner',
nurl: 'https://test.com/win-notice?test=123',
netRevenue: true,
requestId: '2d52001cabd527',
ttl: 30,
width: 300
};
adapter.onBidWon(bid);
expect(utils.triggerPixel.called).to.be.true;

const url = utils.triggerPixel.args[0];

expect(url[0]).to.be.equal('https://test.com/win-notice?test=123&adId=2d52001cabd527&creativeId=12610997325162499419&auctionId=1fdb5ff1b6eaa7&transactionId=c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf&adUnitCode=div-gpt-ad-12345-0&cpm=0.8&currency=USD&originalCpm=0.8&originalCurrency=USD&netRevenue=true&mediaType=banner&timeToRespond=100&status=rendered');
});

it('should not call triggerPixel if nurl does not exist', function () {
const bid = {
adUnitCode: 'div-gpt-ad-12345-0',
adId: '2d52001cabd527',
auctionId: '1fdb5ff1b6eaa7',
transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf',
status: 'rendered',
timeToRespond: 100,
cpm: 0.8,
originalCpm: 0.8,
creativeId: '12610997325162499419',
currency: 'USD',
originalCurrency: 'USD',
height: 250,
mediaType: 'banner',
netRevenue: true,
requestId: '2d52001cabd527',
ttl: 30,
width: 300
};
adapter.onBidWon(bid);
expect(utils.triggerPixel.called).to.be.false;
});
});
});