使用谷歌分析跟踪Wordpress后台生成的PDFs

时间:2023-01-27 15:13:33

I am trying to track PDFs that are dynamically created through a Wordpress backend. This is what I have so far,

我正在尝试追踪通过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>

So basically, I am trying to make it look like in Google Analytics tracking, if one file is named PDF2015 and another is PDF14, it would show up like that in the backend. Tough part is that they are being generated dynamically versus static. Right now, the way I had it before trying to do with php echo $file['name']; I had the label 'Regular' and that is what showed up for all the PDFs instead of the PDF name.

基本上,我试着让它看起来像谷歌分析跟踪,如果一个文件被命名为PDF2015,另一个是PDF14,它会在后端显示出来。难点在于它们是动态生成的,而不是静态生成的。现在,我使用php echo $file['name']之前的方法;我有一个标签“Regular”,这就是所有PDF文件的名称,而不是PDF的名称。

Edit: I have tried doing this, waiting on GA to update:

编辑:我已经尝试过了,等待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>
"; ?>

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

第三个编辑:

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

它工作!如果有人需要帮助,请告诉我!

1 个解决方案

#1


0  

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

This worked for me guys! Let me know if you guys need any help and will glad to help!

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

#1


0  

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

This worked for me guys! Let me know if you guys need any help and will glad to help!

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