cmackay / google-analytics-plugin

Cordova Google Analytics Plugin for Android & iOS
Apache License 2.0
89 stars 43 forks source link

Enhancement to report JavaScript uncaught exceptions #14

Closed ishaigor closed 9 years ago

ishaigor commented 9 years ago

The following function will report all uncaught JavaScript exception. If this can be hooked by plugin itself, it will be awesome. 'analytics' is global variable as in the examples.

        window.onerror = function(msg, file, line) {
            analytics.sendException(file + " ( " + line + "):" + msg, true);
        };

I am able to do it in my app.js of the sample application I am playing with, not sure how to transplant this into the plugin itself.

cmackay commented 9 years ago

Yeah that seems like it would be a useful feature. I could maybe add a function,

analytics.trackUnhandledScriptErrors or some other name

It could optionally take an optional args maybe something like.

analytics.trackUnhandledScriptErrors({
  formatter: function (msg, file, line) {
    // defaults to something like your example message above
    returns 'formatted message';
  },
 fatal: false // defaults to true
})

What do you think? Any other suggestions or ideas for it?

Thanks,

-Craig

ishaigor commented 9 years ago

Craig

This is great. One thing that can be conditionally implemented or enhanced in the future is the new format of the function (which I could not get to work) - see https://html.spec.whatwg.org/multipage/webappapis.html#errorevent: window.onerror = function (errorMsg, url, lineNumber, column, errorObj) { ... } With minimized JS files that will be useful.

Irena

cmackay commented 9 years ago

Hi Irena,

I have added the function and published the updated release. I also added the errorObject to the formatter function if people would like to use but for the default description I thought it might be best to leave it out since it is an object. Thanks again for you feedback and let me know if you think of any other ideas.

Thanks,

-Craig