Commit 00b0cb82 by James Ooi

Fix autotrack

parent 3e0e91b8
...@@ -153,11 +153,15 @@ var Foresight = /** @class */ (function () { ...@@ -153,11 +153,15 @@ var Foresight = /** @class */ (function () {
}); });
}, this.options.observerOptions); }, this.options.observerOptions);
// Start tracking // Start tracking
window.addEventListener('DOMContentLoaded', function () { if (!this.options.defer) {
if (!_this.options.defer) { var domContentLoaded = document.readyState === 'complete' || document.readyState === 'interactive';
_this.start(); if (domContentLoaded) {
this.start();
}
else {
window.addEventListener('DOMContentLoaded', function () { return _this.start(); });
}
} }
});
} }
/** /**
* Start tracking all elements with tracking attributes for events. * Start tracking all elements with tracking attributes for events.
...@@ -257,9 +261,7 @@ var Foresight = /** @class */ (function () { ...@@ -257,9 +261,7 @@ var Foresight = /** @class */ (function () {
Foresight.prototype._trackClicks = function (element) { Foresight.prototype._trackClicks = function (element) {
var _this = this; var _this = this;
// Define listen fucntion // Define listen fucntion
var listener = function (e) { var listener = function (e) { return _this._onTrackedClick(element, e); };
_this._onTrackedClick(element, e);
};
element.addEventListener('click', listener); element.addEventListener('click', listener);
element.addEventListener('auxclick', listener); element.addEventListener('auxclick', listener);
return function () { return function () {
......
...@@ -97,9 +97,14 @@ class Foresight { ...@@ -97,9 +97,14 @@ class Foresight {
}, this.options.observerOptions); }, this.options.observerOptions);
// Start tracking // Start tracking
window.addEventListener('DOMContentLoaded', () => { if (!this.options.defer) {
if (!this.options.defer) { this.start(); } const domContentLoaded = document.readyState === 'complete' || document.readyState === 'interactive';
}); if (domContentLoaded) {
this.start()
} else {
window.addEventListener('DOMContentLoaded', () => this.start());
}
}
} }
/** /**
...@@ -215,9 +220,7 @@ class Foresight { ...@@ -215,9 +220,7 @@ class Foresight {
*/ */
private _trackClicks(element: Element): Function { private _trackClicks(element: Element): Function {
// Define listen fucntion // Define listen fucntion
const listener = (e) => { const listener = (e) => this._onTrackedClick(element, e);
this._onTrackedClick(element, e);
};
element.addEventListener('click', listener); element.addEventListener('click', listener);
element.addEventListener('auxclick', listener); element.addEventListener('auxclick', listener);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment