From 8507272b5112e6ace38aee81477c1e1d43c6bdfd Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Mon, 17 Sep 2018 17:03:12 -0400 Subject: [PATCH] contribute viewability as 0 for inactive tab --- modules/33acrossBidAdapter.js | 12 +++++++++--- test/spec/modules/33acrossBidAdapter_spec.js | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 8fec4415733..497cf9f7110 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -28,7 +28,13 @@ function _createBidResponse(response) { } function _isViewabilityMeasurable() { - return !isIframe() && utils.getWindowTop().document.visibilityState === 'visible'; + return !_isIframe(); +} + +function _getViewability(element, topWin, { w, h } = {}) { + return utils.getWindowTop().document.visibilityState === 'visible' + ? _getPercentInView(element, topWin, { w, h }) + : 0; } // Infer the necessary data from valid bid for a minimal ttxRequest and create HTTP request @@ -41,7 +47,7 @@ function _createServerRequest(bidRequest, gdprConsent) { const minSize = _getMinSize(sizes); const viewabilityAmount = _isViewabilityMeasurable() - ? _getPercentInView(element, utils.getWindowTop(), minSize) + ? _getViewability(element, utils.getWindowTop(), minSize) : NON_MEASURABLE; const contributeViewability = ViewabilityContributor(viewabilityAmount); @@ -221,7 +227,7 @@ function ViewabilityContributor(viewabilityAmount) { return contributeViewability; } -function isIframe() { +function _isIframe() { try { return utils.getWindowSelf() !== utils.getWindowTop(); } catch (e) { diff --git a/test/spec/modules/33acrossBidAdapter_spec.js b/test/spec/modules/33acrossBidAdapter_spec.js index 1fffcd7f55c..c8f0421e1e6 100644 --- a/test/spec/modules/33acrossBidAdapter_spec.js +++ b/test/spec/modules/33acrossBidAdapter_spec.js @@ -337,9 +337,9 @@ describe('33acrossBidAdapter:', function () { }); context('when tab is inactive', function() { - it('returns \'nm\'', function() { + it('returns 0', function() { const ttxRequest = new TtxRequestBuilder() - .withViewabiliuty({amount: spec.NON_MEASURABLE}) + .withViewabiliuty({amount: 0}) .build(); const serverRequest = new ServerRequestBuilder() .withData(ttxRequest)