diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index 8429228d7af..46ad7dfec71 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel, logError } from '../src/utils.js'; +import { _each, isEmpty, buildUrl, deepAccess, pick, logError } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -452,21 +452,20 @@ function getRequestCount() { } function sendTimeoutData(auctionId, auctionTimeout) { - let params = { - aid: auctionId, - ato: auctionTimeout - }; - - try { - let timeoutRequestUrl = buildUrl({ - protocol: 'https', - hostname: BIDDER.HOST, - pathname: BIDDER.TIMEOUT_ENDPOINT, - search: params - }); + const params = { aid: auctionId, ato: auctionTimeout }; + const timeoutRequestUrl = buildUrl({ + protocol: 'https', + hostname: BIDDER.HOST, + pathname: BIDDER.TIMEOUT_ENDPOINT, + search: params, + }); - triggerPixel(timeoutRequestUrl); - } catch (e) {} + fetch(timeoutRequestUrl, { + method: 'GET', + keepalive: true, + }).catch((e) => { + logError('Kargo: sendTimeoutData/fetch threw an error: ', e); + }); } function getImpression(bid) { diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index e24c34dd1ab..a9121a7a59f 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -2030,31 +2030,49 @@ describe('kargo adapter tests', function() { }); }); - describe('onTimeout', function() { + describe('onTimeout', function () { + let fetchStub; + beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); + fetchStub = sinon.stub(global, 'fetch').resolves(); // Stub fetch globally }); afterEach(function () { - utils.triggerPixel.restore(); + fetchStub.restore(); // Restore the original fetch function }); - it('does not call triggerPixel if timeout data is not provided', function() { + it('does not call fetch if timeout data is not provided', function () { spec.onTimeout(null); - expect(utils.triggerPixel.callCount).to.equal(0); + expect(fetchStub.callCount).to.equal(0); }); - it('calls triggerPixel if any timeout data is provided', function() { + it('calls fetch with the correct URLs if timeout data is provided', function () { spec.onTimeout([ - {auctionId: 'test-auction-id', timeout: 400}, - {auctionId: 'test-auction-id-2', timeout: 100}, - {auctionId: 'test-auction-id-3', timeout: 450}, - {auctionId: 'test-auction-id-4', timeout: 500}, + { auctionId: 'test-auction-id', timeout: 400 }, + { auctionId: 'test-auction-id-2', timeout: 100 }, + { auctionId: 'test-auction-id-3', timeout: 450 }, + { auctionId: 'test-auction-id-4', timeout: 500 }, ]); - expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id&ato=400')).to.be.true; - expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-2&ato=100')).to.be.true; - expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-3&ato=450')).to.be.true; - expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-4&ato=500')).to.be.true; + + expect(fetchStub.calledWith( + 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id&ato=400', + { method: 'GET', keepalive: true } + )).to.be.true; + + expect(fetchStub.calledWith( + 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-2&ato=100', + { method: 'GET', keepalive: true } + )).to.be.true; + + expect(fetchStub.calledWith( + 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-3&ato=450', + { method: 'GET', keepalive: true } + )).to.be.true; + + expect(fetchStub.calledWith( + 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-4&ato=500', + { method: 'GET', keepalive: true } + )).to.be.true; }); }); });