Skip to content
A Google Analytics plugin that measures engagement with HTML5 audio/video content.
JavaScript HTML Makefile
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist Updated dist files
example-jquery
example
src Make the library usable without jQuery, use webpack.
.gitignore Make the library usable without jQuery, use webpack.
Makefile
bower.json
license.md
package.json
readme.md Updated README
webpack.config.js
webpack.config.min.js

readme.md

gaplaylength

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:

  • Baseline — triggered when playing
  • 10%
  • 50%
  • 75%
  • 100% — triggered when the playing ends

The above items are only triggered once for the audio/video element.

Install

Bower

bower install gaplaylength

NPM

npm install gaplaylength --save

Manual

Download dist/gaplaylength.min.js or dist/jquery.gaplaylength.min.js.

Usage

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>

Usage with jQuery

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>

Example

See example/index.html and example-jquery/index.html.

Thanks

Thanks to Rob Flaherty (@robflaherty) who created jquery-scrolldepth, which this library is inspired by.

License

Licensed under the BSD 3-clause license, see license.md. See jquery.ga-playlength.js for dependency licenses.

Something went wrong with that request. Please try again.