Skip to content

Commit

Permalink
* add trackReplaySeconds option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Khazov committed Nov 2, 2016
1 parent 2926f0e commit 1d7bbe3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,16 @@ This option goes with the ```secondsPlayed``` event. Every ```secondsPlayedInter
####secondsPlayedMoments

This option goes with the ```secondsPlayed``` event. After each value of ```secondsPlayedMoments``` seconds of the actual playback an event will be sent to GA.
**default:** []
**default:** ```[]```

####trackFiniteSeconds

If set to true and at least one of ```secondsPlayedInterval```, ```secondsPlayedMoments``` options is set, ```seconds played``` events will be triggered.

####trackReplaySeconds
If set to true, ```start``` and ```secondsPlayed``` events will be emitted even after video has ended and then has been started again.
**default:** ```false```

####debug

If set to false, console logs will be ommited
Expand Down
13 changes: 12 additions & 1 deletion dist/videojs.ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

videojs.plugin('ga', function(options) {
var autoLabel, dataSetupOptions, defaultsEventsToTrack, end, error, eventCategory, eventLabel, eventsToTrack, firstplay, fullscreen, getCurrentTime, getCurrentValue, init, interval, isFinite, loaded, parsedOptions, pause, percentsAlreadyTracked, percentsPlayedInterval, play, playing, resize, secondsPlayed, secondsPlayedInterval, secondsPlayedMoments, seekEnd, seekStart, seeking, sendbeacon, startTimeTracking, stopTimeTracking, timeupdate, trackSeconds, trackingTime, volumeChange,
var autoLabel, dataSetupOptions, defaultsEventsToTrack, end, ended, error, eventCategory, eventLabel, eventsToTrack, firstplay, fullscreen, getCurrentTime, getCurrentValue, init, interval, isFinite, loaded, parsedOptions, pause, percentsAlreadyTracked, percentsPlayedInterval, play, playing, resize, secondsPlayed, secondsPlayedInterval, secondsPlayedMoments, seekEnd, seekStart, seeking, sendbeacon, startTimeTracking, stopTimeTracking, timeupdate, trackReplaySeconds, trackSeconds, trackingTime, volumeChange,
_this = this;
if (options == null) {
options = {};
Expand All @@ -27,9 +27,11 @@
percentsPlayedInterval = options.percentsPlayedInterval || dataSetupOptions.percentsPlayedInterval || 10;
secondsPlayedInterval = options.secondsPlayedInterval || dataSetupOptions.secondsPlayedInterval || 60;
secondsPlayedMoments = options.secondsPlayedMoments || dataSetupOptions.secondsPlayedMoments;
trackReplaySeconds = options.trackReplaySeconds;
percentsAlreadyTracked = [];
seekStart = seekEnd = 0;
seeking = false;
ended = false;
trackingTime = false;
secondsPlayed = 0;
isFinite = void 0;
Expand Down Expand Up @@ -113,7 +115,13 @@
}
};
end = function() {
ended = true;
stopTimeTracking();
if (trackReplaySeconds) {
secondsPlayed = 0;
} else {
trackSeconds = false;
}
sendbeacon('end', true);
};
play = function() {
Expand All @@ -123,6 +131,9 @@
if (currentTime > 0 || __indexOf.call(eventsToTrack, 'start') < 0) {
sendbeacon('play', true, currentTime);
}
if (ended && currentTime === 0 && trackReplaySeconds) {
sendbeacon('start', true);
}
seeking = false;
};
playing = function() {
Expand Down
2 changes: 1 addition & 1 deletion dist/videojs.ga.min.js

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

9 changes: 8 additions & 1 deletion src/videojs.ga.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ videojs.plugin 'ga', (options = {}) ->
percentsPlayedInterval = options.percentsPlayedInterval || dataSetupOptions.percentsPlayedInterval || 10
secondsPlayedInterval = options.secondsPlayedInterval || dataSetupOptions.secondsPlayedInterval || 60
secondsPlayedMoments = options.secondsPlayedMoments || dataSetupOptions.secondsPlayedMoments
trackReplaySeconds = options.trackReplaySeconds

# init a few variables
percentsAlreadyTracked = []
seekStart = seekEnd = 0
seeking = false
ended = false
trackingTime = false
secondsPlayed = 0
isFinite = undefined
Expand Down Expand Up @@ -116,14 +118,19 @@ videojs.plugin 'ga', (options = {}) ->
sendbeacon( 'start', true ) if 'start' in eventsToTrack and !isFinite

end = ->
ended = true
stopTimeTracking()
if trackReplaySeconds then secondsPlayed = 0 else trackSeconds = false
sendbeacon( 'end', true )
return

play = ->
startTimeTracking()
currentTime = getCurrentValue()
sendbeacon( 'play', true, currentTime ) if (currentTime > 0 || 'start' not in eventsToTrack)
if (currentTime > 0 || 'start' not in eventsToTrack)
sendbeacon( 'play', true, currentTime )
if ended && currentTime == 0 && trackReplaySeconds
sendbeacon( 'start', true )
seeking = false
return

Expand Down

0 comments on commit 1d7bbe3

Please sign in to comment.