From 8ef4f9d26fd0c134bcc2785d56c56747f9225133 Mon Sep 17 00:00:00 2001 From: Kenan Gillet <1706856+kenan-gillet@users.noreply.github.com> Date: Mon, 21 Sep 2020 08:59:33 -0700 Subject: [PATCH] Update Openx analytics adapter (#5761) * OpenX: track bidRequest.timeout in openxAnalyticsAdapter * OpenX: decode campaign data in openxAnalyticsAdapter --- modules/openxAnalyticsAdapter.js | 11 +++++++---- test/spec/modules/openxAnalyticsAdapter_spec.js | 12 ++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/openxAnalyticsAdapter.js b/modules/openxAnalyticsAdapter.js index 3ee8ab588a9..07966e9e401 100644 --- a/modules/openxAnalyticsAdapter.js +++ b/modules/openxAnalyticsAdapter.js @@ -170,14 +170,15 @@ function isValidConfig({options: analyticsOptions}) { } function buildCampaignFromUtmCodes() { + const location = utils.getWindowLocation(); + const queryParams = utils.parseQS(location && location.search); let campaign = {}; - let queryParams = utils.parseQS(utils.getWindowLocation() && utils.getWindowLocation().search); UTM_TAGS.forEach(function(utmKey) { let utmValue = queryParams[utmKey]; if (utmValue) { let key = UTM_TO_CAMPAIGN_PROPERTIES[utmKey]; - campaign[key] = utmValue; + campaign[key] = decodeURIComponent(utmValue); } }); return campaign; @@ -326,7 +327,7 @@ function onAuctionInit({auctionId, timestamp: startTime, timeout, adUnitCodes}) * @param {PbBidRequest} bidRequest */ function onBidRequested(bidRequest) { - const {auctionId, bids: bidderRequests, start} = bidRequest; + const {auctionId, bids: bidderRequests, start, timeout} = bidRequest; const auction = auctionMap[auctionId]; const adUnitCodeToAdUnitMap = auction.adUnitCodeToAdUnitMap; @@ -341,6 +342,7 @@ function onBidRequested(bidRequest) { source: src, startTime: start, timedOut: false, + timeLimit: timeout, bids: {} }; }); @@ -640,13 +642,14 @@ function buildAuctionPayload(auction) { function buildBidRequestPayload(bidRequestsMap) { return utils._map(bidRequestsMap, (bidRequest) => { - let {bidder, source, bids, mediaTypes, timedOut} = bidRequest; + let {bidder, source, bids, mediaTypes, timeLimit, timedOut} = bidRequest; return { bidder, source, hasBidderResponded: Object.keys(bids).length > 0, availableAdSizes: getMediaTypeSizes(mediaTypes), availableMediaTypes: getMediaTypes(mediaTypes), + timeLimit, timedOut, bidResponses: utils._map(bidRequest.bids, (bidderBidResponse) => { let { diff --git a/test/spec/modules/openxAnalyticsAdapter_spec.js b/test/spec/modules/openxAnalyticsAdapter_spec.js index be7ae6fcdc4..b946efe922d 100644 --- a/test/spec/modules/openxAnalyticsAdapter_spec.js +++ b/test/spec/modules/openxAnalyticsAdapter_spec.js @@ -78,6 +78,7 @@ describe('openx analytics adapter', function() { const bidRequestedOpenX = { auctionId: 'test-auction-id', auctionStart: CURRENT_TIME, + timeout: 2000, bids: [ { adUnitCode: AD_UNIT_CODE, @@ -100,6 +101,7 @@ describe('openx analytics adapter', function() { const bidRequestedCloseX = { auctionId: 'test-auction-id', auctionStart: CURRENT_TIME, + timeout: 1000, bids: [ { adUnitCode: AD_UNIT_CODE, @@ -334,7 +336,7 @@ describe('openx analytics adapter', function() { it('should track values from query params when they exist', function () { sinon.stub(utils, 'getWindowLocation').returns({search: '?' + - 'utm_campaign=test-campaign-name&' + + 'utm_campaign=test%20campaign-name&' + 'utm_source=test-source&' + 'utm_medium=test-medium&' }); @@ -348,7 +350,8 @@ describe('openx analytics adapter', function() { clock.tick(SLOT_LOAD_WAIT_TIME); auction = JSON.parse(server.requests[0].requestBody)[0]; - expect(auction.campaign.name).to.equal('test-campaign-name'); + // ensure that value are URI decoded + expect(auction.campaign.name).to.equal('test campaign-name'); expect(auction.campaign.source).to.equal('test-source'); expect(auction.campaign.medium).to.equal('test-medium'); expect(auction.campaign.content).to.be.undefined; @@ -466,6 +469,11 @@ describe('openx analytics adapter', function() { expect(openxBidRequest.timedOut).to.equal(true); expect(closexBidRequest.timedOut).to.equal(true); }); + + it('should track the timeout value ie timeLimit', function () { + expect(openxBidRequest.timeLimit).to.equal(2000); + expect(closexBidRequest.timeLimit).to.equal(1000); + }); }); describe('when there are bid responses', function () {