Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!