Commit 00b0cb82 by James Ooi

Fix autotrack

parent 3e0e91b8
......@@ -153,11 +153,15 @@ var Foresight = /** @class */ (function () {
});
}, this.options.observerOptions);
// Start tracking
window.addEventListener('DOMContentLoaded', function () {
if (!_this.options.defer) {
_this.start();
if (!this.options.defer) {
var domContentLoaded = document.readyState === 'complete' || document.readyState === 'interactive';
if (domContentLoaded) {
this.start();
}
});
else {
window.addEventListener('DOMContentLoaded', function () { return _this.start(); });
}
}
}
/**
* Start tracking all elements with tracking attributes for events.
......@@ -257,9 +261,7 @@ var Foresight = /** @class */ (function () {
Foresight.prototype._trackClicks = function (element) {
var _this = this;
// Define listen fucntion
var listener = function (e) {
_this._onTrackedClick(element, e);
};
var listener = function (e) { return _this._onTrackedClick(element, e); };
element.addEventListener('click', listener);
element.addEventListener('auxclick', listener);
return function () {
......
......@@ -97,9 +97,14 @@ class Foresight {
}, this.options.observerOptions);
// Start tracking
window.addEventListener('DOMContentLoaded', () => {
if (!this.options.defer) { this.start(); }
});
if (!this.options.defer) {
const domContentLoaded = document.readyState === 'complete' || document.readyState === 'interactive';
if (domContentLoaded) {
this.start()
} else {
window.addEventListener('DOMContentLoaded', () => this.start());
}
}
}
/**
......@@ -215,9 +220,7 @@ class Foresight {
*/
private _trackClicks(element: Element): Function {
// Define listen fucntion
const listener = (e) => {
this._onTrackedClick(element, e);
};
const listener = (e) => this._onTrackedClick(element, e);
element.addEventListener('click', 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