Skip to content

Commit

Permalink
Merge pull request #14 from 33Across/viewability
Browse files Browse the repository at this point in the history
Viewability
  • Loading branch information
glebglushtsov authored Sep 13, 2018
2 parents ac0b586 + 90e5bed commit 9660102
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 91 deletions.
22 changes: 15 additions & 7 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function _createServerRequest(bidRequest, gdprConsent) {
const minSize = _getMinSize(sizes);

const contributeViewability = ViewabilityContributor(
_getPercentInView(element, window.top, minSize)
_getPercentInView(element, spec.getTopWindowSize(), minSize)
);

/*
Expand Down Expand Up @@ -168,15 +168,15 @@ function _getIntersectionOfRects(rects) {
return bbox;
}

function _getPercentInView(element, topWin, { w, h } = {}) {
function _getPercentInView(element, topWinSize, { w, h } = {}) {
const elementBoundingBox = _getBoundingBox(element, { w, h });

// Obtain the intersection of the element and the viewport
const elementInViewBoundingBox = _getIntersectionOfRects([ {
left: 0,
top: 0,
right: topWin.innerWidth,
bottom: topWin.innerHeight
right: topWinSize.width,
bottom: topWinSize.height
}, elementBoundingBox ]);

let elementInViewArea, elementTotalArea;
Expand Down Expand Up @@ -213,6 +213,15 @@ function ViewabilityContributor(viewabilityAmount) {
return contributeViewability;
}

function getTopWindowSize() {
const topWin = utils.getWindowTop();

return {
width: topWin.innerWidth,
height: topWin.innerHeight,
}
}

function isBidRequestValid(bid) {
if (bid.bidder !== BIDDER_CODE || typeof bid.params === 'undefined') {
return false;
Expand Down Expand Up @@ -261,14 +270,13 @@ function getUserSyncs(syncOptions, responses, gdprConsent) {
}
}

const spec = {
export const spec = {
code: BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse,
getTopWindowSize,
getUserSyncs
};

registerBidder(spec);

module.exports = spec;
Loading

0 comments on commit 9660102

Please sign in to comment.