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

196
Views
Log click event on html link using Amplitude SDK

I'm trying to log an event when a <a> link is clicked before navigating to the final destination, this is what I have so far:

<a href="/account" data-event-type="select_account">My account</a>
document.querySelectorAll('a[data-event-type]').forEach(link => 
  link.addEventListener('click', function onLoggableActionClicked(ev) {
    ev.preventDefault();

    amplitude.getInstance().logEvent(link.getAttribute('data-event-type'));
                  
    window.location.href = link.href;
  })
)

The event fires perfectly but the event doesn't get logged, maybe because the request is ended when the browser is redirected?

I tried using a callback but waiting for it makes the navigation impossible:

function onLoggableActionClicked(ev) {
  ev.preventDefault();

  amplitude.getInstance().logEvent(link.getAttribute('data-event-type'), null, function() { window.location.href = link.href });
})

How can I log events for outbound links?

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!