Track Audio Plays, Pauses, Completions using Google Analytics

If you have a website or page that embeds multiple podcasts or audio files on a single page – you’ll want to Track Audio Using Google Analytics like plays, pauses, and completions.

Background: 

I encountered a request to track the number of audio plays on a website. I’d prefer to track this using Google Tag Manager, but the website was built by a third party with only universal analytics so I needed a Javascript solution since the effort to add the Tag Manager container wasn’t going to meet the go live deadline.

Here was some code I found and tweaked to be compatible to track events in Google Analytics on audio files when a user plays, pauses, completes listening to an audio file.

Solution: 

$("audio").bind("play", function(){
ga('send', 'event', 'Audio', "Play", $(this).attr('src'));
});


$("audio").bind("ended", function(){
ga('send', 'event', 'Audio', "Ended", $(this).attr('src'));
});


$("audio").bind("pause", function(){
ga('send', 'event', 'Audio', "Paused", $(this).attr('src'));
});


$("audio").bind("seeked", function(){
ga('send', 'event', 'Audio Seek', "$currentTime", $(this).attr('src'));
});


$("audio a").click(function() {
ga('send', 'event', 'Audio', "Download", $(this).attr('src'));
});

If you need help tracking data about your visitors – Contact Me