Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #28 fixed; Small fix for PercentPlayed tracing for ajax websites/playlists #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
.idea
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,34 @@ The plugin will take in priority options provided in the javascript, followed by

The following options are supported:

####eventCategory
#### eventCategory

This is the ```category``` sent to GA. If you don't know what it is please check [GA's doc](https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide)
**default:** ```'Video'```


####eventLabel
#### eventLabel

This is the ```label``` sent to GA. If you don't know what it is please check [GA's doc](https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide)
**default:** basename of the video path so if the path is ```http://s3.amazonaws.com/pouet.mp4``` the label would be ```pouet```

####eventsToTrack
#### eventsToTrack

The events you want to track. Most of this events are videojs events. Some of them might reflects my needs.
I'm open to add some more if you care to provide a good use case or a pull request.
**default:** every events
```[ 'loaded', 'percentsPlayed', 'start', 'end', 'seek', 'play', 'pause', 'resize', 'volumeChange', 'error', 'fullscreen']```
```[ 'loadedmetadata', 'percentsPlayed', 'start', 'end', 'seek', 'play', 'pause', 'resize', 'volumeChange', 'error', 'fullscreen']```

Most of the events are selft explanatory, here's the ones that may need more details:

- ```percentsPlayed```: will send an event every X percents. X being defined by the option ```percentsPlayedInterval```.

####percentsPlayedInterval
#### percentsPlayedInterval

This options goes with the ```percentsPlayed``` event. Every ```percentsPlayedInterval``` percents an event will be sent to GA.
**default:** 10

####debug
#### debug

If set to false, console logs will be ommited
**default:** ```false```
Expand Down
18 changes: 10 additions & 8 deletions demo/multiple-videos.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@
<meta charset="utf-8" />
<title>videojs-ga DEMO Multiple videos on same page</title>
<link href="../libs/video-js-4.6.1/video-js.css" rel="stylesheet" type="text/css">
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="../libs/video-js-4.6.1/video.dev.js"></script>
<script src="../dist/videojs.ga.js"></script>
</head>

<body>
<video id="video" controls preload="none" class="video-js vjs-default-skin" width="640" height="480">
<video id="video1" controls preload="none" class="video-js vjs-default-skin" width="640" height="480">
<source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
<source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">
</video>

<video id="video" controls preload="none" class="video-js vjs-default-skin" width="640" height="480">
<video id="video2" controls preload="none" class="video-js vjs-default-skin" width="640" height="480">
<source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
<source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">
</video>

<script>
$(document).ready(function(){
$('video').each(function() {
videojs(this.id, {}, function() {
this.ga();
});
})
});

$('video').each(function() {
videojs(this.id, {}, function() {
this.ga();
});
})

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
11 changes: 6 additions & 5 deletions dist/videojs.ga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* videojs-ga - v0.4.2 - 2015-02-06
* Copyright (c) 2015 Michael Bensoussan
* videojs-ga - v0.4.2 - 2017-05-25
* Copyright (c) 2017 Michael Bensoussan
* Licensed MIT
*/
(function() {
Expand All @@ -12,13 +12,13 @@
options = {};
}
dataSetupOptions = {};
if (this.options()["data-setup"]) {
parsedOptions = JSON.parse(this.options()["data-setup"]);
if (this.options_["data-setup"]) {
parsedOptions = JSON.parse(this.options_["data-setup"]);
if (parsedOptions.ga) {
dataSetupOptions = parsedOptions.ga;
}
}
defaultsEventsToTrack = ['loaded', 'percentsPlayed', 'start', 'end', 'seek', 'play', 'pause', 'resize', 'volumeChange', 'error', 'fullscreen'];
defaultsEventsToTrack = ['loadedmetadata', 'percentsPlayed', 'start', 'end', 'seek', 'play', 'pause', 'resize', 'volumeChange', 'error', 'fullscreen'];
eventsToTrack = options.eventsToTrack || dataSetupOptions.eventsToTrack || defaultsEventsToTrack;
percentsPlayedInterval = options.percentsPlayedInterval || dataSetupOptions.percentsPlayedInterval || 10;
eventCategory = options.eventCategory || dataSetupOptions.eventCategory || 'Video';
Expand All @@ -28,6 +28,7 @@
seekStart = seekEnd = 0;
seeking = false;
loaded = function() {
percentsAlreadyTracked = [];
if (!eventLabel) {
eventLabel = this.currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i, '');
}
Expand Down
6 changes: 3 additions & 3 deletions dist/videojs.ga.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions src/videojs.ga.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
videojs.plugin 'ga', (options = {}) ->
# this loads options from the data-setup attribute of the video tag
dataSetupOptions = {}
if @options()["data-setup"]
parsedOptions = JSON.parse(@options()["data-setup"])
if @options_["data-setup"]
parsedOptions = JSON.parse(@options_["data-setup"])
dataSetupOptions = parsedOptions.ga if parsedOptions.ga

defaultsEventsToTrack = [
'loaded', 'percentsPlayed', 'start',
'loadedmetadata', 'percentsPlayed', 'start',
'end', 'seek', 'play', 'pause', 'resize',
'volumeChange', 'error', 'fullscreen'
]
Expand All @@ -34,6 +34,7 @@ videojs.plugin 'ga', (options = {}) ->
seeking = false

loaded = ->
percentsAlreadyTracked = [] #we should reset percentAlreadyTracked on each new video loaded. Otherwise we get "percentsPlayed" only for first video in row. Actual for ajax sites or/and playlists
unless eventLabel
eventLabel = @currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i,'')

Expand Down