Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Automatic Javascript Error Tracking with Piwik! #4977

Closed
mattab opened this issue Apr 10, 2014 · 50 comments
Closed

New: Automatic Javascript Error Tracking with Piwik! #4977

mattab opened this issue Apr 10, 2014 · 50 comments
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.

Comments

@mattab
Copy link
Member

mattab commented Apr 10, 2014

Using the new powerful Event Tracking functionality, we can implement Javascript Errors Tracking within piwik.js.

The goal of this feature is to keep track automatically of any javascript errors or exception that happen during the rendering of the page, or any time after the initial rendering.

There are lots of tools that provide Error tracking and we would like to implement a basic, yet useful, alternative as part of Piwik Data Analytics platform!

Todo

  • FAQ
  • User Guide?
  • JS test
@tsteur
Copy link
Member

tsteur commented Apr 10, 2014

In 588e689: refs #4977 added a new method to the tracker to enableJSErrorTracking. This is beta... feedback is welcome...

@tsteur
Copy link
Member

tsteur commented Apr 10, 2014

In 128d75a: refs #4977 enable JS error tracking in Piwik UI (if tracking in Piwik UI is activated)

@tsteur
Copy link
Member

tsteur commented Apr 10, 2014

In 5ef610b: refs #4977 include piwik tracker as early as possible to make sure we track js errors

@tsteur
Copy link
Member

tsteur commented Apr 10, 2014

In 5d74768: refs #4977 make JSLint happy

@hpvd
Copy link

hpvd commented Apr 10, 2014

Replying to Thomas Steur:

include piwik tracker as early as possible to make sure we track js errors

makes sense, but may result in problems if users use tools to protect their privacy (like extension "ghostery" in FF ) which blocks piwik.

If Piwik script is blocked sometimes the complete site is not usable any more because the following js is blocked/broken too..

@tsteur
Copy link
Member

tsteur commented Apr 11, 2014

In 0f43631: refs #4977 make clear that only uncaught errors are tracked

@mattab
Copy link
Member Author

mattab commented Apr 17, 2014

Interesting, Google Analytics just released Javascript Exception Tracking as well! https://developers.google.com/analytics/devguides/collection/analyticsjs/exceptions

@mattab
Copy link
Member Author

mattab commented May 28, 2014

See also #5257 Application Performance Management & Monitoring

@mattab mattab added this to the 2.5.0 - Piwik 2.5.0 milestone Jul 8, 2014
@mattab mattab modified the milestones: Mid term, Short term Dec 1, 2014
@mattab
Copy link
Member Author

mattab commented Dec 1, 2014

There are now many tools offering useful and usable JavaScript error tracking such as airbrake.io or raygun.io

@szepeviktor
Copy link
Contributor

Is it a working feature or a planned one?
If you're planning, please consider stealing code from https://github.com/MindscapeHQ/raygun4js (AJAX error, stack trace etc.)
https://github.com/getsentry/raven-js is also using https://github.com/csnover/TraceKit
But there is https://github.com/stacktracejs/stacktrace.js also.

@tsteur
Copy link
Member

tsteur commented Jul 31, 2015

It is working in general but only very basic. We simply track all errors as events for now but hope to provide similar enhanced features some day than others do

@hpvd
Copy link

hpvd commented Apr 4, 2016

"it is working in general but only very basic"
is there any doc how to use it? Do one has to enable it or should it work without any config directly "out of box"?

@tsteur
Copy link
Member

tsteur commented Apr 4, 2016

Looks like there is no documentation for it indeed. There's a bit of documentation here: https://github.com/piwik/piwik/blob/2.16.0/js/piwik.js#L5869-L5886 and to activate it you can call _paq.push(['enableJSErrorTracking']);.

It is very very basic though and I would suggest to first give it a try as it will add many different event actions and event names to your event reports in case you are using them for something else currently (it could give you a less good overview of action and names in event reports)

@mattab mattab modified the milestones: Long term, Mid term Dec 5, 2016
@sgiehl sgiehl added the c: Design / UI For issues that impact Matomo's user interface or the design overall. label Apr 11, 2017
@wei1215583760
Copy link

thanks for your reply @RMastop
9fe2ec4ca3eaa5459acd8a634deddd92
there are responses to piwik, but it did not carry error message. Can you give me some advice?

@wei1215583760
Copy link

d31e8c9c62f7b94287b0578a936710da
@RMastop

this is full image

@RMastop
Copy link
Contributor

RMastop commented Aug 15, 2017

@wei1215583760 When should the js error occur? Could you post the HTML of the page?

@wei1215583760
Copy link

wei1215583760 commented Aug 15, 2017

this is my website code, index.html. And i add an error <script>a+b</scrip, and it can post HTML, but i can not track the error @RMastop ....sad

t>, ths whole

@wei1215583760
Copy link

@RMastop
f4c0c82f22434f40a2536331f8511fbc
this is the page in chrome browser

@wei1215583760
Copy link

@RMastop do you know where i the error message it stores as log data?

@RMastop
Copy link
Contributor

RMastop commented Aug 15, 2017

@wei1215583760 I tried to reproduce the issue, but no call is triggered after the JS error. Without the call to the piwik server, no need to search for it in the database.

@wei1215583760
Copy link

thanks a lot for your patience, but i still do not know how to track the error, maybe this error can not be tracked? do you know what kind of error can be tracked?

@wei1215583760
Copy link

Now i want to make sure that this function can track errors and show it with piwik dashboard. if you have some examples, can you give me example errors?@RMastop

@RMastop
Copy link
Contributor

RMastop commented Aug 15, 2017

Hi @wei1215583760,

As documented, Could you put the Piwik tracking code all the way to the top op the HTML, just below <HEAD>
After this change Javascript errors are tracked as events.

e_c:JavaScript Errors
e_a:http://127.0.0.1:8888/jserrordemo/:164:3
e_n:Uncaught ReferenceError: a is not defined
idsite:4
rec:1

@wei1215583760
Copy link

wei1215583760 commented Aug 15, 2017

do you mean put the tracking code like this ? but it still have no reponse ...sad
where do you get your message? in action=>event?
@RMastop

@Findus23
Copy link
Member

You can also try running the tracking script non async/deferred as explained here: https://developer.piwik.org/guides/ab-tests/browser

This will slow down your site a bit but will make sure that piwik is loaded before the error occurs.

@RMastop
Copy link
Contributor

RMastop commented Aug 15, 2017

@wei1215583760 just below the opening <HEAD>
image

@wei1215583760
Copy link

thanks for your help, @Findus23 @RMastop , I change the tracking script using synchronous method, and it worked.
image
thanks a lot for your kind heart

@Findus23
Copy link
Member

maybe now that we have a documentation on how to run piwik non-asynchronous, we should maybe we should also document this feature. (And warn about the performance decline)

@wei1215583760
Copy link

Yes, but asynchronous method did not work for error tracking in my case. Maybe this case will be a good guide for other users

@wei1215583760
Copy link

82bb9f56ee563244b873f09993e70add
Additionaly, i can track js error as the following picture shows, but how can i track the full trace back including at "at abc (demo1.js:11) at efg (demo1.js:16)" @RMastop @Findus23
25f45f6048e3e248ae720a8cb405b8b5

@wei1215583760
Copy link

If i want to make sure where the error happened, i need to know the accurate message

@wei1215583760
Copy link

@tsteur do you know how to track full trace back using js? If there are some errors, I want to find it more easily with trace back information.

@Findus23
Copy link
Member

@wei1215583760
Currently piwik doesn't add the stacktrace, but it shouldn't be that hard to add:

Check https://github.com/piwik/piwik/blob/3.x-dev/js/piwik.js#L6500-L6543
and https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror

At least in chrome (I am not sure about other browsers) the stacktrace should be accessable via error.stack

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
https://stackoverflow.com/a/4200200

@wei1215583760
Copy link

I have used error tracking for several days, it worked well. And I want to know where the information placed in the datatable. Do you know where these error strings are stored? @Findus23 @RMastop I am sorry to trouble you.

@wei1215583760
Copy link

again

@mattab
Copy link
Member Author

mattab commented Sep 18, 2017

Do you know where these error strings are stored?

They're stored as Actions in log_link_visit_action and log_action tables see: https://developer.piwik.org/guides/persistence-and-the-mysql-backend#action-types

@nvinayvarma189
Copy link

@wei1215583760
Currently piwik doesn't add the stacktrace, but it shouldn't be that hard to add:

Check https://github.com/piwik/piwik/blob/3.x-dev/js/piwik.js#L6500-L6543
and https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror

At least in chrome (I am not sure about other browsers) the stacktrace should be accessable via error.stack

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack
https://stackoverflow.com/a/4200200

Hey @Findus23, I wanted to know if the latest version of matomo can print the stack trace or not. I couldn't find much documentation regarding this.

Also, I've seen that JSErrorTracking can only track the uncaught exceptions and not errors regarding missing resources (cdn links, external CSS and js, etc). Has this changed now? and if not is there a way that one can track these errors through any other means?

Thanks

@Findus23
Copy link
Member

Findus23 commented Jul 1, 2020

@nvinayvarma189
As far as I know nothing changed since the last post here. But you can still use Event Tracking to track any arbitrary event and data so including Javascript errors if you write the code that triggers a Matomo event when they happen.

@mattab
Copy link
Member Author

mattab commented Oct 7, 2020

Documented this feature in: https://matomo.org/faq/how-to/how-do-i-enable-basic-javascript-error-tracking-and-reporting-in-matomo-browser-console-error-messages/

Noted the two main limitations i'm aware of at the end:

  • currently the stack trace is not recorded, which makes it sometimes harder to troubleshoot.
  • when you enable this feature it will start tracking errors as events. If you already use Events for other purposes, these new error events might somehow "pollute" your Event reports and add noise. As a workaround, you may create Custom reports to filter out the "JavaScript Errors" events if needed.

@mattab
Copy link
Member Author

mattab commented Oct 7, 2020

Will close this for now. If you use this feature, please open new issues for specific feedback.

@mattab mattab closed this as completed Oct 7, 2020
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

No branches or pull requests

9 participants