Ok Yandex! Where are our “Reach Goals”?

The story about Yandex.Metrika ReachGoal, the girl Lida and about the fact that there are no intractable problems



The world is not perfect, the world wide world is not even more perfect. Sometimes, you can close your eyes to this. But only not when a beautiful girl named Lida from the “marketing department” is standing in front of you, looks into your eyes and asks the question: “For some reason, in Ya. Metric, the data that I see the order funnel is different from those which I see in our account system. And we have more orders. ”

Since girls with beautiful eyes need to be loved and courted in every way, it was decided to connect the logging of events that occur to customers during their checkout.

Not particularly hoping for any interesting effect and therefore not slyly wisely, a service was quickly added that registers events occurring on the frontend in the browsers of visitors to our site.

First of all, we were interested in events that could have occurred during the execution of the Ya.Metriki code, namely, yaCounterXXXXXX.reachGoal ().

So, we put everywhere where we need to catch the exception and send these events to the server:

try {
    yaCounterXXXXXX.reachGoal("EVENT_XXX");
 } catch(e) {
    $.get("/front/service/event", {event: "YM-warning", goal: " EVENT_XXX ", message: e.message});
 }

Time passes, we remember that we threw the bait, but the catch was not checked.
We go to watch the logs, and to our surprise we see about the following there:

[2018-04-17 09:04:51.431]  [BASKET_LOAD] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36]
 [2018-04-17 09:09:18.082]  [BASKET_LOAD] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:59.0) Gecko/20100101 Firefox/59.0]
[2018-04-17 09:09:21.369]  [BASKET_LOAD] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:59.0) Gecko/20100101 Firefox/59.0]
[2018-04-17 09:09:24.990]  [BASKET_LOAD] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:59.0) Gecko/20100101 Firefox/59.0]
[2018-04-17 09:09:27.001]  [] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:59.0) Gecko/20100101 Firefox/59.0]
[2018-04-17 09:12:44.778]  [ORDER_CREATED] [yaCounterXXXXXX is not defined] [Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:59.0) Gecko/20100101 Firefox/59.0]
... и так далее

A quick calculation showed that about 3..4..5% of the events in the basket pass by Ya.Metriki. Lida was right. And if the girl is right, you need to do something. Although when a girl is wrong, you still need to do something.

Begin to look for the cause. The counter is installed correctly, the overwhelming majority of events are recorded by it correctly. We are trying to google the presence of similar problems among our colleagues. There was nothing like that.

Yandex's techsupport responded with a letter containing a link to the metric meter installation documentation, for which, of course, a special, warm thanks to them!

I will not describe all the hypotheses that we have tried. The bottom line is that at the time of loading the page, the Yandex.Metricka counter code is not loaded into the client’s browser and is not initialized there. It may be an ad blocker and / or trackers for tracking, there may be some network problems between the client and the Yandex server (this is unlikely).

I had to take Lida by the hand, look into her bottomless eyes and reluctantly tell the harsh truth: “Lida, you will have to accept the fact that some visitors to our site will not receive the“ checkout / cancellation of the order ”events in J. Metric. But we will definitely come up with something. ”

Summer passed, autumn was coming to an end, as Lida appeared on the threshold of the office again. In her eyes full of tears, it became clear that those unfortunate percentages passing by prevented her from showing the authorities beautiful reports and thereby receiving an annual bonus, which she had already included in her budget for a trip to Thailand for the New Year holidays.

The heart trembled. The whole team of the front end group was assembled, and in a tough form he was ordered to “dig from here to dinner!” The task was set to solve this problem by any means! And not that !!! But Lida would not be able to go to Thailand ...

The Frontend did not want to dig for a long time and almost immediately was offered a quick solution:

// Делаем локальную копию скрипта яндекс.метрики и загружаем ее тем, // кому не повезло загрузить ее с сервера Яндекса// Локальная копия периодически синхронизируется var n = document.getElementsByTagName("script")[0],
         s = document.createElement("script");
     s.src = "/js/yaScriptLocal.js";
     n.parentNode.insertBefore(s, n);

The result of this decision can be seen on the graph; it is an analysis of the event log itself.



As you can see, the number of errors dropped to almost 0.

If you don’t yet check the success of Yandex.Metrica script downloads on your website, be sure to check. You can also expect interesting discoveries.

Disclaimer: I have an understanding that the above solution is far from optimal. I would be happy to hear thoughts and opinions on this matter.

Also popular now: