Fix errors in tracking pixel and lightbox

This commit is contained in:
Jocelyn Badgley (Twipped) 2020-03-02 20:27:34 -08:00
parent a7e266a558
commit 640c3ac1a8
2 changed files with 17 additions and 27 deletions

View File

@ -1,11 +1,11 @@
(function (window, document, navigator) { (function () {
const me = document.currentScript; const me = window.document.currentScript;
const url = me.getAttribute('data-url'); const url = me.getAttribute('data-url');
const iOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); const iOS = !!window.navigator.platform && /iPad|iPhone|iPod/.test(window.navigator.platform);
const vendor = navigator.vendor; const vendor = window.navigator.vendor;
const doNotTrack = navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack; const doNotTrack = window.navigator.doNotTrack || window.navigator.msDoNotTrack || window.doNotTrack;
let tid = !doNotTrack && window.localStorage.getItem('tid'); let tid = !doNotTrack && window.localStorage.getItem('tid');
if (!tid && !doNotTrack) { if (!tid && !doNotTrack) {
@ -13,17 +13,14 @@
window.localStorage.setItem('tid', tid); window.localStorage.setItem('tid', tid);
} }
const body = document.body;
const html = document.documentElement;
const SESSION_DATA = { const SESSION_DATA = {
tid, tid,
start: Date.now(), start: Date.now(),
end: null, end: null,
max_scroll: 0, max_scroll: 0,
language: navigator.userLanguage || navigator.language, language: window.navigator.userLanguage || window.navigator.language,
href: window.location.pathname, href: window.location.pathname,
referrer: document.referrer, referrer: window.document.referrer,
}; };
// listen for all the exit events // listen for all the exit events
@ -38,14 +35,14 @@
// scroll tracking // scroll tracking
window.addEventListener('scroll', function () { window.addEventListener('scroll', function () {
const page_height = Math.max( const page_height = Math.max(
body.scrollHeight, window.document.body.scrollHeight,
body.offsetHeight, window.document.body.offsetHeight,
html.clientHeight, window.document.documentElement.clientHeight,
html.scrollHeight, window.document.documentElement.scrollHeight,
html.offsetHeight, window.document.documentElement.offsetHeight,
); );
const viewport_height = Math.max(html.clientHeight, window.innerHeight || 0); const viewport_height = Math.max(window.document.documentElement.clientHeight, window.innerHeight || 0);
const max_scroll = Math.max(SESSION_DATA.max_scroll, window.scrollY); const max_scroll = Math.max(SESSION_DATA.max_scroll, window.scrollY);
const viewed = max_scroll === 0 ? 0 : Math.round(((max_scroll + viewport_height) / page_height) * 100); const viewed = max_scroll === 0 ? 0 : Math.round(((max_scroll + viewport_height) / page_height) * 100);
@ -89,4 +86,4 @@
// a hack necessary for Firefox and Safari refresh / back button // a hack necessary for Firefox and Safari refresh / back button
} }
} }
}(window, document, navigator)); }());

View File

@ -1,6 +1,6 @@
(function ($) { $(function () {
$('.lightbox, .gutter').each(function () { $('.lightbox, .gutter, .tweet-entities').each(function () {
$(this).magnificPopup({ $(this).magnificPopup({
delegate: 'a.lb', delegate: 'a.lb',
type: 'image', type: 'image',
@ -13,14 +13,7 @@
gallery: { gallery: {
enabled: true, enabled: true,
}, },
zoom: {
enabled: true,
duration: 300, // don't foget to change the duration also in CSS
opener: function (element) {
return element.find('img');
},
},
}); });
}); });
}(window.jQuery)); });