From 60d8fd68828d1b7d4a6da79fe69506ef8ea5d0e6 Mon Sep 17 00:00:00 2001 From: Jeremy Sadwith Date: Wed, 1 Jun 2022 13:02:25 -0400 Subject: [PATCH] Kargo Bid Adapter: onTimeout Support (#8449) * Kargo Bid Adapter: Use currency from Bid Response * Kargo Bid Adapter: Fix failed test * Kargo Bid Adapter: adding media type to bid response, supporting vastXml response (#8426) * kargo adapter - adding mediaType to bid response, conditionally set vastXml field * kargo adapter - updating tests * Kargo Bid Adapter: onTimeout Support (#6) * Adding additional param * Adding response time function * Remove debug * Updating response time log to be set by bid response * Adding screen width/height to request * Test fix * Test fix * Removing interpretResponse signaling * Simplifying send data function Co-authored-by: Wei Wong Co-authored-by: Andy Rusiecki --- modules/kargoBidAdapter.js | 33 ++++++++++++++++++++++- test/spec/modules/kargoBidAdapter_spec.js | 27 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) 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'); + }); + }); });