K
K
Konstantin2019-06-05 09:38:23
JavaScript
Konstantin, 2019-06-05 09:38:23

What is an alternative way to set Yandex goals?

Hello, my sites (wordpress) have JS event targets on buttons, but the code disappears from time to time.
Most likely, the engine itself auto-formats the code, since such code is not clear to it.
Here is the code I put in:

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

Is there an alternative how to insert this onclick ? Hang up somehow on a class or span, and add a span inside the link tag?
I would be grateful for examples.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Gribanov, 2019-06-05
@gradk

<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');
    });
  });
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question