Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realvu Analytics Adapter: improve flagging of 'display:none' containers #7182

Merged
merged 10 commits into from
Jul 21, 2021
62 changes: 40 additions & 22 deletions modules/realvuAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,28 +306,46 @@ export let lib = {
if (!restored) {
a.target = z.questA(a.div);
let target = (a.target !== null) ? a.target : a.div;
a.box.w = Math.max(target.offsetWidth, a.w);
a.box.h = Math.max(target.offsetHeight, a.h);
let q = z.findPosG(target);
let pad = {};
pad.t = z.padd(target, 'Top');
pad.l = z.padd(target, 'Left');
pad.r = z.padd(target, 'Right');
pad.b = z.padd(target, 'Bottom');
let ax = q.x + pad.l;
let ay = q.y + pad.t;
a.box.x = ax;
a.box.y = ay;
if (a.box.w > a.w && a.box.w > 1) {
ax += (a.box.w - a.w - pad.l - pad.r) / 2;
}
if (a.box.h > a.h && a.box.h > 1) {
ay += (a.box.h - a.h - pad.t - pad.b) / 2;
}
if ((ax > 0 && ay > 0) && (a.x != ax || a.y != ay)) {
a.x = ax;
a.y = ay;
z.writePos(a);
if (window.getComputedStyle(target).display == 'none') {
let targSibl = target.previousElementSibling; // for 'none' containers on mobile define y as previous sibling y+h
if (targSibl) {
let q = z.findPosG(targSibl);
a.x = q.x;
a.y = q.y + targSibl.offsetHeight;
} else {
target = target.parentNode;
let q = z.findPosG(target);
a.x = q.x;
a.y = q.y;
}
a.box.x = a.x;
a.box.y = a.y;
a.box.w = a.w;
a.box.h = a.h;
} else {
a.box.w = Math.max(target.offsetWidth, a.w);
a.box.h = Math.max(target.offsetHeight, a.h);
let q = z.findPosG(target);
let pad = {};
pad.t = z.padd(target, 'Top');
pad.l = z.padd(target, 'Left');
pad.r = z.padd(target, 'Right');
pad.b = z.padd(target, 'Bottom');
let ax = q.x + pad.l;
let ay = q.y + pad.t;
a.box.x = ax;
a.box.y = ay;
if (a.box.w > a.w && a.box.w > 1) {
ax += (a.box.w - a.w - pad.l - pad.r) / 2;
}
if (a.box.h > a.h && a.box.h > 1) {
ay += (a.box.h - a.h - pad.t - pad.b) / 2;
}
if ((ax > 0 && ay > 0) && (a.x != ax || a.y != ay)) {
a.x = ax;
a.y = ay;
z.writePos(a);
}
}
}
let vtr = ((a.box.w * a.box.h) < 242500) ? 49 : 29; // treashfold more then 49% and more then 29% for "oversized"
Expand Down