Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
Clicking on anchor tag will only excute part of a function

I am currently facing an issue where I have event listeners running for my client's website which track all hover and clicks on the website. We have 4 clients and our code works fine on 3 of them but it does not work correctly on the 1 client's website.

We are running the following code when a click is triggered:

async function objectClick(obj) {
  var tag = obj.target;
  if (tag.nodeName == 'IMG') {
    objectName = tag.src;
  } else {
    objectName = tag.innerText || tag.textContent || tag.value;
  }

  var data_tag = tag.getAttribute("data-*");

  if (data_tag != null) {
    if (data_tag.includes("abc")) {
      var layout = JSON.parse(window.localStorage.getItem(page));
      layout.ctr = 1;
      window.localStorage.setItem(page, JSON.stringify(layout))
      await sendToHistory(uid, url, JSON.stringify(layout));
    } else if (data_tag.includes("reward")) {
      var layout = JSON.parse(window.localStorage.getItem(page));
      layout.reward = 1;
      window.localStorage.setItem(page, JSON.stringify(layout))
      await sendToHistory(uid, url, JSON.stringify(layout));
    }
  }


  if (data_tag === "abc" || data_tag === "reward") {
    await sendToJourney(uid, "Clicked", -1, tag.nodeName, JSON.stringify({ text: objectName, data_nostra: null }), url, page);

  } else {
    await sendToJourney(uid, "Clicked", -1, tag.nodeName, JSON.stringify({ text: objectName, data_nostra: data_nostra_tag }), url, page);

  }

}

For most of our clients, all the code runs in the function runs, including the sendToJourney function. For this client, after sendToHistory runs, the page switches and sendToJourney is not triggered. Do you know why this is?

sendToJourney and sendToHistory are functions that send some data to an API. Let me know if you need more information. Lastly, the client's website is created using Elementor which is a WordPress plugin. 2 of the other 4 clients also use Elementor but the function is fully executed for them but just not for this 1 client. Is there something that can be preventing the code from fully executing?

We have tried using obj.preventDefault but we cannot get the event to be triggered afterwards once our code is executed so what solution could be use here?

I call objectClick() by attaching an event listener as such:

(async function (document) {
  await initData()
  var trackable = document.querySelectorAll("img,button,p,h1,h2,h3,h4,h5,h6,a,span,input[type='submit'],[data-*]");
  for (var i = 0; i < trackable.length; i++) {
    trackable[i].addEventListener('mouseover', onHover, false);
    trackable[i].addEventListener('mouseout', offHover, false);
    trackable[i].addEventListener('click', objectClick, false);
  }
})(document);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda