https://github.com/leighmcculloch/gaplaylength.js
A Google Analytics plugin that measures engagement with HTML5 audio/video content.
https://github.com/leighmcculloch/gaplaylength.js
Last synced: about 1 month ago
JSON representation
A Google Analytics plugin that measures engagement with HTML5 audio/video content.
- Host: GitHub
- URL: https://github.com/leighmcculloch/gaplaylength.js
- Owner: leighmcculloch
- License: bsd-3-clause
- Created: 2014-06-06T05:27:44.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-28T14:57:12.000Z (almost 10 years ago)
- Last Synced: 2025-05-09T02:11:30.630Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 5.13 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# 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 endsThe above items are only triggered once for the audio/video element.
## Install
### Bower
```bash
bower install gaplaylength
```### NPM
```bash
npm install gaplaylength --save
```### Manual
Download [dist/gaplaylength.min.js](dist/gaplaylength.min.js) or [dist/jquery.gaplaylength.min.js](dist/jquery.gaplaylength.min.js).
## Usage
Include this library after your Google Analytics tracking snippet.
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
});
## Usage with jQuery
Include this library after your Google Analytics tracking snippet, and jQuery.
$(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
});
});
## Example
See [example/index.html](example/index.html) and [example-jquery/index.html](example-jquery/index.html).## Thanks
Thanks to Rob Flaherty ([@robflaherty](https://twitter.com/robflaherty)) who created [jquery-scrolldepth](https://github.com/robflaherty/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.