使用Google Analytics跟踪Wordpress后端生成的PDF


Tracking PDFs generated by Wordpress backend with Google Analytics

我正在尝试跟踪通过Wordpress后端动态创建的PDF。这就是我目前所拥有的,

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

所以基本上,我试图让它看起来像在谷歌分析跟踪中,如果一个文件名为PDF2015,另一个文件为PDF14,它会在后端显示为那样。困难的是,它们是动态生成的,而不是静态生成的。现在,我在尝试使用php echo$file['name']之前的方式;我有一个标签"Regular",这是所有PDF中显示的内容,而不是PDF名称。

编辑:我已经尝试过了,正在等待GA更新:

<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>
"; ?>

第二次编辑:

<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>
"; ?>   

第三次编辑:

成功了!如果有人需要帮助,请告诉我!

<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>
"; ?>   

这对我很管用!如果你们需要任何帮助,请告诉我,我很乐意帮助你们!