Skip to content
Permalink
Browse files

v1.0.3

 - Avoid blocking ops
 - Annotate code
 - Less code weight
 - Better memory consumption
  • Loading branch information...
dr-dimitru committed May 6, 2016
1 parent bdc659b commit 2e71a531c9130dc3f7bf32c3bce3b62fc30590db
Showing with 73 additions and 41 deletions.
  1. +3 −3 .versions
  2. +3 −1 CHANGELOG.md
  3. +3 −0 HISTORY.md
  4. +58 −31 lib/analytics.js
  5. +1 −1 lib/analytics.min.js
  6. +2 −2 package.js
  7. +3 −3 package.json
@@ -1,3 +1,3 @@
meteor@1.1.13
ostrio:analytics@1.0.2
underscore@1.0.7
meteor@1.1.14
ostrio:analytics@1.0.3
underscore@1.0.8
@@ -1 +1,3 @@
See full change-log at [releases on GitHub](https://github.com/VeliovGroup/ostrio-analytics/releases)
Changelog
========
For full changelog see [releases on GitHub](https://github.com/VeliovGroup/ostrio-analytics/releases)
@@ -0,0 +1,3 @@
History
========
For full package history see [releases on GitHub](https://github.com/VeliovGroup/ostrio-analytics/releases)
@@ -1,6 +1,8 @@
'use strict';
/* Method names and class properties is truncated in mind of smaller code size */
;(function(root) {
var SD = (function() {
/* Screen Detector Class */
var SD = (function () {
function SD() {
this.s = window.screen || screen || {};
this.h = this.s.height;
@@ -21,15 +23,17 @@
}
}

SD.prototype.d = function() {
/* Detect screen orientation */
SD.prototype.d = function () {
if (this.w >= this.h) {
return '-';
} else {
return '|';
}
};

SD.prototype.toJ = function() {
/* Export screen info to JSON */
SD.prototype.toJ = function () {
var obj = {};
obj['4a'] = this.w + 'x' + this.h;
obj['4b'] = (window.innerWidth || window.clientHeight) + 'x' + (window.innerHeight || window.clientHeight);
@@ -41,6 +45,7 @@
return SD;
})();

/* Tracking Class */
var OTC = (function() {
function OTC(sid, auto) {
if (auto === undefined) { auto = true; }
@@ -50,13 +55,13 @@
this.fc = false;
this.sid = sid;
this.DNT = !!parseInt(navigator.doNotTrack || 0);
this.ver = 102;
this.ver = 103;
this.EUC = encodeURIComponent || function(str) {return str;};
var self = this;

if (window.Image === undefined) {
this.iL = document.createElement('img');
} else {
this.iL = new Image();
}
this._hcWr = function (e) {
self._hc(e);
};

if (!this.DNT) {
if (auto) {
@@ -69,6 +74,7 @@
}
}

/* Handle Clicks */
OTC.prototype._hc = function hcl(e) {
var target = e.currentTarget;
if (target && target.href && target.href !== this.ch + '#' && target.href !== this.ch + '/#') {
@@ -81,39 +87,40 @@
}
};

OTC.prototype._lL = function() {
var self = this;
var elements = Array.prototype.slice.call(document.getElementsByTagName('a'));
var handleClick = function (e) { self._hc(e); };
/* Watch a (anchor) elements clicks */
OTC.prototype._lL = function () {
var elements = Array.prototype.slice.call(document.getElementsByTagName('a'));

for (var i = elements.length - 1; i >= 0; i--) {
this._rE(elements[i], 'click', handleClick);
this._aE(elements[i], 'click', handleClick);
this._rE(elements[i], 'click', this._hcWr);
this._aE(elements[i], 'click', this._hcWr);
}
};

OTC.prototype._s = function() {
/* Auto-Start method */
OTC.prototype._s = function () {
var self = this;
setTimeout(function(){ return self.track.apply(self); }, 1);
self._lL();

/* Watch DOM changes */
var MO = window.MutationObserver || window.WebKitMutationObserver;

if (MO) {
var observer = new MO(function(mutations){
var observer = new MO(function (mutations) {
for (var i = mutations.length - 1; i >= 0; i--) {
for (var j = mutations[i].addedNodes.length - 1; j >= 0; j--) {
if (mutations[i].addedNodes[j].nodeName) {
if (mutations[i].addedNodes[j].nodeName === 'A') {
self._aE(mutations[i].addedNodes[j], 'click', self.handleClick);
self._aE(mutations[i].addedNodes[j], 'click', self._hcWr);
}
}
}

for (var k = mutations[i].removedNodes.length - 1; k >= 0; k--) {
if (mutations[i].removedNodes[k].nodeName) {
if (mutations[i].removedNodes[k].nodeName === 'A') {
self._rE(mutations[i].removedNodes[k], 'click', self.handleClick);
self._rE(mutations[i].removedNodes[k], 'click', self._hcWr);
}
}
}
@@ -125,39 +132,42 @@
self._aE(document.body, 'DOMSubtreeModified', self.lL);
}

var hc = function() {
/* Listen for events when user navigates inside page */
/* Listen for events when user leaves page or closing browser */
var hc = function () {
if (!self.fc) {
self.track();
}
};

var hx = function() {
var hx = function () {
if (!self.fc) {
self.track('&7=' + self._gH(), false);
}
};

self._aE(window, 'hashchange', hc);
self._aE(window, 'popstate', hc);
self._aE(window, 'unload', hx);
self._aE(window, 'beforeunload', hx);
self._aE(document, 'beforeunload', hx);
self._aE(document.body, 'beforeunload', hx);

/* Listen for History events */
var _history = window.History || History || window.history || history;

if (_history && _history.Adapter) {
_history.Adapter.bind(window, 'statechange', hc);
}

/* Fallback to long-polling URI changes */
setInterval(function (){
if (self.ch !== self.loc.href && !self.fc) {
self.track();
self._lL();
}
}, 750);

var origWoE = window.onerror;

/* Listen for Global Errors */
var origWoE = window.onerror;
window.onerror = function(msg, url, line) {
self.pushEvent('[Global Error]', 'Error: ' + msg + '. File: ' + url.replace(self.loc.origin, '') + ' On line: ' + line);
if (origWoE) {
@@ -166,6 +176,7 @@
};
};

/* Bulletproof addEventListener */
OTC.prototype._aE = function(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
@@ -174,6 +185,7 @@
}
};

/* Bulletproof removeEventListener */
OTC.prototype._rE = function(obj, type, fn) {
if (obj.removeEventListener) {
obj.removeEventListener(type, fn, false);
@@ -182,6 +194,7 @@
}
};

/* Custom events method */
OTC.prototype.pushEvent = function(key, value) {
if (!this.DNT) {
if (key && value && key.length && value.length) {
@@ -199,35 +212,48 @@
}
};

/* Return current location href */
OTC.prototype._gH = function() {
return this.loc.href;
};

/* Send tracking info */
OTC.prototype.track = function(q, delay) {
if (!this.DNT) {
if (!q) { q = ''; }
var self = this;
var iT = function() {
if (self.ch !== self.loc.href || /&(8|3)=/.test(q)) {
var imageLoader;
var query = '?';
query += '6=' + encodeURIComponent(self._gH());
query += '6=' + self.EUC(self._gH());

if (!~q.indexOf('&3=')) {
query += '&2=' + encodeURIComponent(document.title);
query += '&4=' + encodeURIComponent(self.scr);
query += '&2=' + self.EUC(document.title);
query += '&4=' + self.EUC(self.scr);
if (document.referrer && !~document.referrer.indexOf(self.loc.origin)) {
query += '&1=' + encodeURIComponent(document.referrer);
query += '&1=' + self.EUC(document.referrer);
}

var locale = navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage || false;

if (locale) {
query += '&5=' + encodeURIComponent(locale);
query += '&5=' + self.EUC(locale);
}
self.ch = self.loc.href;
}

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

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

imageLoader.src = 'https://analytics.ostr.io/' + self.sid + '.gif' + query + q + '&9=' + ((''+(+new Date())).substr(-7))+ '&v=' + self.ver;

setTimeout(function() {
self.fc = false;
@@ -247,6 +273,7 @@
return OTC;
})();

/* NPM; Browserify: AMD; */
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = OTC;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,13 +1,13 @@
Package.describe({
name: 'ostrio:analytics',
version: '1.0.2',
version: '1.0.3',
summary: 'Visitor\'s analytics tracking code for ostr.io service',
git: 'https://github.com/VeliovGroup/ostrio-analytics',
documentation: 'README.md'
});

Package.onUse(function(api) {
api.versionsFrom('1.3');
api.versionsFrom('1.0');
api.addFiles('./lib/analytics.js', 'client');
api.export('OstrioTrackerClass', 'client');
});
@@ -1,6 +1,6 @@
{
"name": "ostrio-analytics",
"version": "1.0.2",
"version": "1.0.3",
"description": "Visitor's analytics tracking code for ostr.io service",
"main": "./lib/analytics.js",
"scripts": {
@@ -25,8 +25,8 @@
"bounce rate",
"ostr.io"
],
"author": "Dmitriy A. (http://veliovgroup.com)",
"license": "BSD 3-Clause",
"author": "Dmitriy A. (https://veliovgroup.com)",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/VeliovGroup/ostrio-analytics/issues"
},

0 comments on commit 2e71a53

Please sign in to comment.
You can’t perform that action at this time.