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

316
Vistas
NextJS call gtag("event") from api route

I'd like to log an event on Google Analytics when an api route is opened.

My gtag implementation is as follows at the moment:

export const logEvent = ({ action, category, label, value }: LogEventProps) => {
  (window as any).gtag("event", action, {
    event_category: category,
    event_label: label,
    value: value,
  });
};

Problem is that it relies on a window for logs to be fired, which is undefined, understandably so, whenever I'm calling this method from an api route.

I couldn't find any valuable information on how to log an event from the server side.

A work-around might be to have the api redirect to a blank page that logs the event, but I don't love the idea and wonder if there's a better approach.

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