What an alternative way to install Yandex goal?

Welcome on my sites (wordpress) are goals of the JS events on the buttons, but from time to time the code disappears.
Most likely autoformation the engine code, because it the code is not clear.

Here is the code I put:
<a onclick="ym(20084554, 'reachGoal', 'tel'); return true;" href="tel:+7812 331 17 xx">+7 (812) 331-17-xx </a>


Is there an alternative to how to insert this onclick ? To hang like that on a class or span and add the span inside the link tag?
I would be grateful for examples
March 23rd 20 at 19:08
1 answer
March 23rd 20 at 19:10
Solution
<a class="ym-trigger" href="tel:+7812 331 17 xx">+7 (812) 331-17-xx </a>

window.onload = function () {
 document.querySelectorAll('.ym-trigger').forEach(function ($el) {
 $el.addEventListener('click', function () {
 window.ym(20084554, 'reachGoal', 'tel');
});
});
};
Thank you! - Sally_Haag14 commented on March 23rd 20 at 19:13

Find more questions by tags Yandex.MetricaJavaScript