Track PDF files created by Wordpress backend using Google Analytics

I am trying to track PDF files that are dynamically created through the Wordpress backend. This is what I still have

<a class="download" onClick="_gaq.push(['_trackEvent', '<?php echo $file['name']; ?>', 'Download', 'Test']);" href="<?php echo $file['url']; ?>"> Download <?php echo strtoupper($file_extension[0]); ?> </a> 

Basically, I am trying to make it look like Google Analytics tracking, if one file is called PDF2015 and the other is PDF14, it will display the same as in the backend. The tough part is that they are generated dynamically and statically. Right now, as I did, before trying to do with php echo $ file ['name']; I had the "Normal" shortcut, and this is what appeared for all PDF files instead of the PDF name.

Edit: I tried to do this while waiting for a GA update:

 <a class="download" href="<?php echo $file['url']; ?>">Download <?php echo strtoupper($file_extension[0]); ?></a><br /> <?php echo " <script type='text/javascript'> $('.download').on('click',function(){ _gaq.push(['_trackEvent',"."'".$file['url']."'".", 'Download', 'Test']); }); </script> "; ?> 

Second edit:

 <a class="download" href="<?php echo $file['url']; ?>" id="<?php echo `strstr($title, ' ', true); ?>">Download <?php echo strtoupper($file_extension[0]); ?></a><br />` <?php echo " <script type='text/javascript'> $("."'#".strstr($title, ' ', true)."'".").on('click',function(){ _gaq.push(['_trackEvent',"."'".$title."'".", 'Download', 'Test']); }); </script> "; ?> 

Third Editing:

It worked! If anyone needs help with this, let me know!

+6
source share
1 answer
 <a class="download" href="<?php echo $file['url']; ?>" id="<?php echo `strstr($title, ' ', true); ?>">Download <?php echo strtoupper($file_extension[0]); ?></a><br />` <?php echo " <script type='text/javascript'> $("."'#".strstr($title, ' ', true)."'".").on('click',function(){ _gaq.push(['_trackEvent',"."'".$title."'".", 'Download', 'Test']); }); </script> "; ?> 

It worked for me guys! Let me know if you guys need any help and will be happy to help!

0
source

Source: https://habr.com/ru/post/989533/


All Articles