Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

300
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda