Dynamically Attach Google Analytics Event Handler to File Download

Attaching to all attr pdf’s

$( document ).ready(function() {
    //attach event dispatcher to all links that are pdf files
    //register event in analtyics
    $('a[href*=".pdf"]').click(function(e) {
        ga('send', 'event', 'PDF', 'download',  $(this).attr('href'), 1);
    });   
});

Leave a Reply

Your email address will not be published.