Skip to content

Commit

Permalink
Kargo Bid Adapter: onTimeout Support (prebid#8449)
Browse files Browse the repository at this point in the history
* 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 (prebid#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 <wwong@kargo.com>
Co-authored-by: Andy Rusiecki <andy.rusiecki@gmail.com>
  • Loading branch information
3 people authored Jun 1, 2022
1 parent 74e7d20 commit 60d8fd6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
33 changes: 32 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 @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
27 changes: 27 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 @@ -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',
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 60d8fd6

Please sign in to comment.