Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-04-10 08:59:36 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-04-10 08:59:36 +0400
commit588e68948a3b68223ceecc7a2575db4a220be8c4 (patch)
tree5273746be0da56e3f926fb7508556669805e98ac /js
parentb865e2f7179df3f5e7d2bff099e569aa2e24802b (diff)
refs #4977 added a new method to the tracker to enableJSErrorTracking. This is beta... feedback is welcome...
Diffstat (limited to 'js')
-rw-r--r--js/piwik.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/js/piwik.js b/js/piwik.js
index 193b3f612b..ca72b847cb 100644
--- a/js/piwik.js
+++ b/js/piwik.js
@@ -424,7 +424,7 @@ if (typeof JSON2 !== 'object') {
setConversionAttributionFirstReferrer,
disablePerformanceTracking, setGenerationTimeMs,
doNotTrack, setDoNotTrack, msDoNotTrack,
- addListener, enableLinkTracking, setLinkTrackingTimer,
+ addListener, enableLinkTracking, enableJSErrorTracking, setLinkTrackingTimer,
setHeartBeatTimer, killFrame, redirectFile, setCountPreRendered,
trackGoal, trackLink, trackPageView, trackSiteSearch, trackEvent,
setEcommerceView, addEcommerceItem, trackEcommerceOrder, trackEcommerceCartUpdate,
@@ -1072,6 +1072,8 @@ if (typeof Piwik !== 'object') {
locationHrefAlias = locationArray[1],
configReferrerUrl = locationArray[2],
+ enableJSErrorTracking = false,
+
// Request method (GET or POST)
configRequestMethod = 'GET',
@@ -2826,6 +2828,51 @@ if (typeof Piwik !== 'object') {
},
/**
+ * Enable JavaScript Error Tracking
+ *
+ * If enabled, uncaught JavaScript Errors will be tracked as an event by defining a
+ * window.onerror handler. If a window.onerror handler is already defined we will make
+ * sure to call this previously registered error handler after tracking the error.
+ *
+ * By default we return false in the window.onerror handler to make sure the error still
+ * appears in the browser's console etc. Note: Some older browsers might behave differently
+ * so it could happen that an actual JavaScript error will be suppressed.
+ * If a window.onerror handler was registered we will return the result of this handler.
+ *
+ * Make sure not to overwrite the window.onerror handler after enabling the JS error
+ * tracking as the error tracking won't work otherwise. To capture all JS errors we
+ * recommend to include the Piwik JavaScript tracker in the HTML as early as possible.
+ * If possible directly in <head></head> before loading any other JavaScript.
+ */
+ enableJSErrorTracking: function () {
+ if (enableJSErrorTracking) {
+ return;
+ }
+
+ enableJSErrorTracking = true;
+ var onError = window.onerror;
+
+ window.onerror = function(message, url, linenumber, column, error) {
+ trackCallback(function () {
+ var category = 'JavaScript Errors';
+
+ var action = url + ':' + linenumber;
+ if (column) {
+ action += ':' + column
+ }
+
+ logEvent(category, action, message);
+ });
+
+ if (onError) {
+ return onError(message, url, linenumber, column, error);
+ }
+
+ return false;
+ };
+ },
+
+ /**
* Disable automatic performance tracking
*/
disablePerformanceTracking: function () {