Skip to content

Commit

Permalink
Merge pull request #16 from 33Across/viewability
Browse files Browse the repository at this point in the history
contribute viewability as 0 for inactive tab
  • Loading branch information
glebglushtsov committed Sep 17, 2018
2 parents 525684b + 8507272 commit d502156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -221,7 +227,7 @@ function ViewabilityContributor(viewabilityAmount) {
return contributeViewability;
}

function isIframe() {
function _isIframe() {
try {
return utils.getWindowSelf() !== utils.getWindowTop();
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d502156

Please sign in to comment.