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

214
Vistas
ga.getAll() breaks a function making it return undefined in a javascript GTM variable

So, I created "javascript code" variable in GTM and trying to get clientID via ga.getAll, and have the following code:

function foo() {
  var trackers = ga.getAll();
  if (trackers.length > 0) {
    return  trackers[0].get('trackingId') === 'UA-188398635-1' ? trackers[0].get('clientId') : 'nonon';
  }
}

But it always returns undefined, even if I make it return a string constant 'asdasd' - having ga.getAll in the code is enough for the function to break. And the most confusing thing - the same code works in debug console just fine. Help please.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since foo returns undefined, that means that trackers.length is 0. Try this:

function foo() {
    var trackers = ga.getAll();
    if(trackers.length >0) {
        return  trackers[0].get('trackingId') === 'UA-188082465-1' ? trackers[0].get('clientId') : 'nonon';
    } else {
        return 'This is not undefined';
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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