-
Notifications
You must be signed in to change notification settings - Fork 1
/
js-watson.js
44 lines (35 loc) · 1.17 KB
/
js-watson.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* JS-Watson
*
* Copyright 2012, Shyam Habarakada
* Licensed under MIT.
*
*/
(function(global) {
var _i = this;
// Try to initialize with the default google analytics async queue
var _gaq = window._gaq;
// Based on http://bit.ly/ILq9ak
var _pathExtractRegEx = /^[a-z]+:\/\/\/?[^\/]+(\/[^?]*)/i;
// default path under which errors page-views will be reported
var _pathPrefix = "/javascript_error";
// Override the google analytics async queue object used for reporting
_i.setGaq = function(gaQueue) {
_gaq = gaQueue;
}
// Override the path under which error page-views are reported
_i.setBasePath = function(path) {
_pathPrefix = path;
}
// Function to register as a callback for window.onerror (or invoke from
// within a window.onerror handler.
_i.trackUnhandledError = function(message, url, linenumber) {
try {
if(_gaq && _gaq.push && typeof(_gaq.push) == "function") {
var url = _pathPrefix + (_pathExtractRegEx.exec(url))[1] + "?line=" + linenumber + "&message=" + encodeURIComponent(message);
_gaq.push(['_trackPageview',url]);
}
} catch(e) {};
};
global["JsWatson"] = _i;
})(this);