I am trying to track PDFs that are dynamically created through a WordPress backend. This is what I have so far,
<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.
Edit: I have tried doing this, waiting on GA to 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 Edit:
It worked! If anyone needs help with this, let me know!
This worked for me guys! Let me know if you guys need any help and will glad to help!