diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index 1842231721b..80b3d83167e 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -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'; @@ -55,6 +55,10 @@ export const spec = { }, bidIDs, bidSizes, + device: { + width: window.screen.width, + height: window.screen.height + }, prebidRawBidRequests: validBidRequests }, spec._getAllMetadata(tdid, bidderRequest.uspConsent, bidderRequest.gdprConsent)); const encodedParams = encodeURIComponent(JSON.stringify(transformedParams)); @@ -133,6 +137,15 @@ export const spec = { return syncs; }, supportedMediaTypes: SUPPORTED_MEDIA_TYPES, + onTimeout: function(timeoutData) { + if (timeoutData == null) { + return; + } + + timeoutData.forEach((bid) => { + this._sendTimeoutData(bid.auctionId, bid.timeout); + }); + }, // PRIVATE _readCookie(name) { @@ -263,6 +276,24 @@ export const spec = { } catch (e) { return ''; } + }, + + _sendTimeoutData(auctionId, auctionTimeout) { + let params = { + aid: auctionId, + ato: auctionTimeout, + }; + + try { + let timeoutRequestUrl = buildUrl({ + protocol: 'https', + hostname: 'krk.kargo.com', + pathname: '/api/v1/event/timeout', + search: params + }); + + triggerPixel(timeoutRequestUrl); + } catch (e) {} } }; registerBidder(spec); diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 1515ed0820e..4733c2dcdb3 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -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(); @@ -249,6 +250,10 @@ describe('kargo adapter tests', function () { 2: [[320, 50], [300, 250], [300, 600]], 3: [[320, 50], [300, 250], [300, 600]] }, + device: { + width: screen.width, + height: screen.height, + }, userIDs: { kargoID: '5f108831-302d-11e7-bf6b-4595acd3bf6c', clientID: '2410d8f2-c111-4811-88a5-7b5e190e475f', @@ -683,4 +688,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'); + }); + }); });