S
S
SergeyKisliy2016-09-27 19:52:50
JavaScript
SergeyKisliy, 2016-09-27 19:52:50

How to capture only one event and ignore the rest?

Hello.
I have a calculator on my site, I need to track interaction with it and send an event to Yandex Metrica. If you send an event on the focus of an element or on the appearance of the final price, then the events will be sent a lot of times, because users frequently change settings and data. Is there a way to send only one event?
Ps The calculator displays the price as the value of at least one field changes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kovalsky, 2016-09-27
@SergeyKisliy

Just as an option:

function listener() {
  console.log('This message will get logged only once');
  Element.removeEventListener(event, listener);
};
    
Element.addEventListener(event, listener);

S
Sergey, 2016-09-28
@void01

stopImmediatePropagation,
upd: I didn't read the statement, in your case I would recommend using events like window.onunload i.e. when leaving the page,
or option 2 - timeouts
every time the field is changed, setting the timeout to 20 seconds, for example, and restarting it on repeated events, and in case of triggering, send the metric

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question