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

303
Views
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 answers
Answer question

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