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

176
Vistas
Google Tag Manager custom javascript variable not set correctly in Google Analytics in production

I have created the following custom javascript variable in Google Tag Manager:

function() {
  return {{Click Text}} || {{Click Element}};
}

which uses the built in variables Click Text and Click Element. I am using this variable as the label of a tag, which is triggered by any click.

This works perfectly well when the tags are triggered from localhost and the labels arrive correctly to Google Analytics (I'm using universal analytics). However, for my production website the label always shows up as (not set) in Google Analytics. What causes this discrepancy?

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

0

The reason this was not working for me was because I had a content security policy enabled on my production website, and for custom javascript variables to work with a CSP they need script-src: 'unsafe-eval' in the policy. This was also hard to debug because there is no error raised in the console about the CSP blocking the script.

To resolve this you can either add the above to the policy or alternatively use custom variable templates to run javascript in a way that doesn't require unsafe-eval. Unfortunately, this doesn't work for my example using {{Click Element}}, since it is not allowed in the template, but it works well for other situations where you might want to use a custom javascript variable.

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