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

Kargo Bid Adapter: onTimeout Support #6

Merged
merged 1 commit into from
May 23, 2022
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
23 changes: 22 additions & 1 deletion modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each } from '../src/utils.js';
import { _each, buildUrl, triggerPixel } from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
Expand Down Expand Up @@ -133,6 +133,27 @@ export const spec = {
return syncs;
},
supportedMediaTypes: SUPPORTED_MEDIA_TYPES,
onTimeout: function(timeoutData) {
if (timeoutData == null) {
return;
}

timeoutData.forEach((bid) => {
let params = {
aid: bid.auctionId,
ato: bid.timeout,
};

let timeoutRequestUrl = buildUrl({
protocol: 'https',
hostname: 'krk.kargo.com',
pathname: '/api/v1/event/timeout',
search: params
});

triggerPixel(timeoutRequestUrl);
});
},

// PRIVATE
_readCookie(name) {
Expand Down
23 changes: 23 additions & 0 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect, assert} from 'chai';
import {spec} from 'modules/kargoBidAdapter.js';
import {config} from 'src/config.js';
const utils = require('src/utils');

describe('kargo adapter tests', function () {
var sandbox, clock, frozenNow = new Date();
Expand Down Expand Up @@ -683,4 +684,26 @@ describe('kargo adapter tests', function () {
safelyRun(() => expect(getUserSyncsWhenForbidden()).to.be.an('array').that.is.empty);
});
});

describe('timeout pixel trigger', function () {
let triggerPixelStub;

beforeEach(function () {
triggerPixelStub = sinon.stub(utils, 'triggerPixel');
});

afterEach(function () {
utils.triggerPixel.restore();
});

it('should call triggerPixel utils function when timed out is filled', function () {
spec.onTimeout();
expect(triggerPixelStub.getCall(0)).to.be.null;
spec.onTimeout([{ auctionId: '1234', timeout: 2000 }]);
expect(triggerPixelStub.getCall(0)).to.not.be.null;
expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://krk.kargo.com/api/v1/event/timeout');
expect(triggerPixelStub.getCall(0).args[0]).to.include('aid=1234');
expect(triggerPixelStub.getCall(0).args[0]).to.include('ato=2000');
});
});
});