A Google Analytics plugin that measures engagement with HTML5 audio/video content.
BSD-3-CLAUSE License
A Google Analytics plugin that measures engagement with audio/video content by tracking how much of a HTML5 audio/video player a visitor plays. The plugin supports Universal Analytics, Classic Google Analytics, and Google Tag Manager.
The following time portions are reported:
The above items are only triggered once for the audio/video element.
bower install gaplaylength
npm install gaplaylength --save
Download dist/gaplaylength.min.js or dist/jquery.gaplaylength.min.js.
Include this library after your Google Analytics tracking snippet.
<script src="gaplaylength.min.js"></script>
<script>
var element = document.querySelector('audio,video');
gaplaylength.init(element, {
/* audioTime: if true, the time in seconds of the
* audio will be included with the event. Default: true */
audioTime: true,
/* userTiming: if true, the time in seconds since page load
* will be included in the event. Default: true */
userTiming: true
});
</script>
Include this library after your Google Analytics tracking snippet, and jQuery.
<script src="jquery.gaplaylength.min.js"></script>
<script>
$(function() {
$('audio').gaPlayLength({
/* audioTime: if true, the time in seconds of the
* audio will be included with the event. Default: true */
audioTime: true,
/* userTiming: if true, the time in seconds since page load
* will be included in the event. Default: true */
userTiming: true
});
});
</script>
See example/index.html and example-jquery/index.html.
Thanks to Rob Flaherty (@robflaherty) who created jquery-scrolldepth, which this library is inspired by.
Licensed under the BSD 3-clause license, see license.md
. See jquery.ga-playlength.js
for dependency licenses.