Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda