📜 ⬆️ ⬇️

Monitoring errors on site pages using Yandex.Metrics

Today I came across an interesting post about monitoring errors on the site. The described method has a drawback - it is applicable only for React.
After reading the post, I immediately remembered the web viewer. If a person called me, oh, I clicked somewhere, it jumped out, found a mistake on the site, I would be very happy to see what he did, and not to ask a person a lot of questions, wasting his time.

It turned out that everything is so simple that the implementation of the idea took me only a minute.

The only way to convey the fact of an error on the page - goal.

I created a javascript event and called the target Js Error.
')


Next, I added to the counter code the sending of events when an error occurred.

<script type="text/javascript" > (function (d, w, c) { (w[c] = w[c] || []).push(function() { try { w.yaCounter%id % = new Ya.Metrika({ id:%id %, clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true //    }); } catch(e) { } }); var n = d.getElementsByTagName("script")[0], s = d.createElement("script"), f = function () { n.parentNode.insertBefore(s, n); }; s.type = "text/javascript"; s.async = true; s.src = "https://mc.yandex.ru/metrika/watch.js"; if (w.opera == "[object Opera]") { d.addEventListener("DOMContentLoaded", f, false); } else { f(); } })(document, window, "yandex_metrika_callbacks"); window.addEventListener("error", function(event){ //        . -,   - ,  ,       . console.log(event); //  ,    yaCounter%id %.reachGoal('ERROR'); }); </script> <noscript><div><img src="https://mc.yandex.ru/watch/%id %" style="position:absolute; left:-9999px;" alt="" /></div></noscript> 

At this point, my experiment was successfully completed. If you go to a webcam, you can see the achievement of goals, which means that an error occurred during your current visit.



Of course, for the full analysis of errors this will not be enough. I think it is worth making an error handler that will display information directly on the page if the site is viewed through a web browser. You can also divide mistakes into levels, or even make certain events of particular interest into a separate goal. For monitoring 404, 500 and other errors, you can add a counter to the error template with a separate goal and send it immediately after the initialization of the counter.

Very pleased that along with the recording of user actions, we get a lot of information that can help with further checks.


There are also disadvantages of this method:

  1. To determine the error you need to view the visit
  2. The number of goals in the metric is limited. 200 targets available
  3. Pages on which the counter is not installed will not be monitored.
  4. The web visitor does not record all visits from users, but only 120 thousand visits per day and stores them for 15 days.

I hope this simple way can be useful to someone.

UPD:
In the comments altervision suggested that you can pass on the parameters of the visit in the reachGoal method. This may be enough to send error messages.

Source: https://habr.com/ru/post/344802/


All Articles