Sadly I can’t help you with your code problem. But from my own experience, I would advise you to move away from Yandex anyways. As far as I know, Yandex is located in Russia and they aren’t very considered with peoples and your own data. I remember creating an account with Yandex and instantly receiving a ton more spam. Even worse, if you are using the website recordings feature they can get the email address of a customer filling out the form on your sites. So you are putting their information at risk too.
I have been using Hotjar for a while now. And the data you can collect from your websites is even better than with Yandex. They are located in Europe and are always trying to stay up-to-date with current legal privacy requirements.
Perhaps your problem gets solved automatically by moving to a Hotjar integration.