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

213
Views
ga.getAll() rompe una función haciéndola regresar indefinida en una variable javascript GTM

Entonces, creé la variable "código javascript" en GTM e intenté obtener el ID de cliente a través de clientID , y ga.getAll el siguiente código:

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

Pero siempre devuelve undefined , incluso si hago que devuelva una constante de cadena 'asdasd' : tener ga.getAll en el código es suficiente para que la function se rompa. Y lo más confuso: el mismo código funciona bien en la consola de depuración. Ayuda por favor.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Dado que foo devuelve undefined, eso significa que trackers.length es 0. Prueba esto:

 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 Report
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!