diff --git a/README.md b/README.md index 99db567..a091447 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Place the following on your page, and replace the logglyKey value with the key p ``` diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index 217ef81..ad272c2 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -15,6 +15,7 @@ function LogglyTracker() { this.key = false; + this.sendConsoleErrors = false; } function setKey(tracker, key) { @@ -23,6 +24,30 @@ setInputUrl(tracker); } + function setSendConsoleError(tracker, sendConsoleErrors) { + tracker.sendConsoleErrors = sendConsoleErrors; + + if(tracker.sendConsoleErrors === true){ + var _onerror = window.onerror; + //send console error messages to Loggly + window.onerror = function (msg, url, line, col){ + tracker.push({ + category: 'BrowserJsException', + exception: { + message: msg, + url: url, + lineno: line, + colno: col, + } + }); + + if (_onerror && typeof _onerror === 'function') { + _onerror.apply(window, arguments); + } + }; + } + } + function setInputUrl(tracker) { tracker.inputUrl = LOGGLY_INPUT_PREFIX + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN) @@ -64,6 +89,10 @@ return; } + if(data.setConsoleError !== undefined) { + setSendConsoleError(self, data.setConsoleError); + } + if(data.logglyKey) { setKey(self, data.logglyKey); return;