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

298
Vistas
Pushing PHP variables to dataLayer using JS

I heard from a good friend that people in this community can be very helpful and good-hearted so I'd love some help from you peops!

I've been trying to push php variables to the datalayer using the .push() method in javascript (for google tag manager and google analytics). Below is the code snippet to better understand what's happening.

 <?php . . . . . . ?>
    
    <script language='javascript'>

     $(window).on("load", function() { 

     var variable1 = <?php echo $variable1_php; ?>;
     var variable2 = <?php echo $variable2_php; ?>;
     var variable3 = <?php echo $variable3_php; ?>;

      window.dataLayer.push({
             'event' : 'eventName',
             'variable1_for_gtm': $variable1,
             'variable2_for_gtm': $variable2,
              'variable3_for_gtm': $variable3,
});

});

</script>;
        
    <?php . . . . . .

What am I missing exactly? Thanks a lot!! P.S. Other events are correctly being tracked by GTM and recorded in GA.

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

0

Instead of using a $ sign just use variable names without it. $ sign is used for PHP variable names but not javascript.

 var variable1 = <?php echo $variable1_php; ?>;
 var variable2 = <?php echo $variable2_php; ?>;
 var variable3 = <?php echo $variable3_php; ?>;

window.dataLayer.push({
             'event' : 'eventName',
             'variable1_for_gtm': variable1,
             'variable2_for_gtm': variable2,
              'variable3_for_gtm': variable3,
});
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