Skip to content

Commit

Permalink
npm.1.2.1|a.1.3.1|b.207
Browse files Browse the repository at this point in the history
- Add support for Beacon API
- Minor overall optimizations
  • Loading branch information
dr-dimitru committed Mar 1, 2020
1 parent 4f47c2c commit c33b3cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = (function () {
var self = this;
this.sid = sid;
this.DNT = !!parseInt(navigator.doNotTrack || 0);
this.version = 206;
this.version = 207;
this.sending = false;
this.loc = location || window.location || document.location;
this.current = '';
Expand Down Expand Up @@ -41,13 +41,13 @@ module.exports = (function () {
/* Listen for Global Errors */
var _onerror = window.onerror;
window.onerror = function (_msg, _url, _line, _column) {
var url = _url || '';
var msg = _msg || 'N/A';
var url = (_url || '') + ' at ' + self.loc.href;
var line = _line || '0';
var column = _column || '0';

if (!!~url.indexOf(self.loc.origin)) {
self.pushEvent('[Global Error]', 'Error: ' + msg + '. File: ' + url.replace(self.loc.origin, '').replace(self.loc.origin, '') + ' At: ' + line + ':' + column);
self.pushEvent('[Global Error]', 'Error: ' + msg + '. File: ' + url.replace(self.loc.origin, '') + ' at ' + self.loc.href + ':' + line + ':' + column);
}
if (_onerror) {
_onerror.apply(this, arguments);
Expand Down Expand Up @@ -122,7 +122,6 @@ module.exports = (function () {

setTimeout(function () {
self.current = self.loc.href;
var imageLoader;

if (!~query.indexOf('?3=')) {
query = ('?6=' + self._euc(self.loc.href.trim().substring(0, 1024)) + query);
Expand All @@ -132,17 +131,23 @@ module.exports = (function () {
}
}

if (window.Image === undefined) {
imageLoader = document.createElement('img');
var url = 'https://analytics.ostr.io/' + self.sid + '.gif' + query + '&9=' + (('' + (+new Date())).substr(-7)) + '&v=' + self.version;
if (navigator && navigator.sendBeacon) {
navigator.sendBeacon(url);
} else {
imageLoader = new Image();
}
var imageLoader;
if (window.Image === undefined) {
imageLoader = document.createElement('img');
} else {
imageLoader = new Image();
}

imageLoader.onload = function () {
imageLoader = null;
};
imageLoader.onload = function () {
imageLoader = null;
};

imageLoader.src = 'https://analytics.ostr.io/' + self.sid + '.gif' + query + '&9=' + (('' + (+new Date())).substr(-7)) + '&v=' + self.version;
imageLoader.src = url;
}
self.sending = false;
}, 64);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/analytics.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c33b3cf

Please sign in to comment.