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

198
Visualizações
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
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