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

amd support #15

Open
wants to merge 1 commit 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
266 changes: 139 additions & 127 deletions dist/videojs.ga.js
Original file line number Diff line number Diff line change
@@ -1,144 +1,156 @@
/*
* videojs-ga - v0.4.1 - 2014-06-06
* videojs-ga - v0.4.1 - 2014-11-11
* Copyright (c) 2014 Michael Bensoussan
* Licensed MIT
*/
(function() {
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 dataSetupOptions, defaultsEventsToTrack, end, error, eventCategory, eventLabel, eventsToTrack, fullscreen, loaded, parsedOptions, pause, percentsAlreadyTracked, percentsPlayedInterval, play, resize, seekEnd, seekStart, seeking, sendbeacon, timeupdate, volumeChange;
if (options == null) {
options = {};
(function(factory) {
if (typeof exports === "object" && typeof require === "function") {
return module.exports = factory(require("video"));
} else if (typeof define === "function" && define.amd) {
return define(["./video"], function(vjs) {
return factory(vjs);
});
} else {
return factory(window.videojs);
}
dataSetupOptions = {};
if (this.options()["data-setup"]) {
parsedOptions = JSON.parse(this.options()["data-setup"]);
if (parsedOptions.ga) {
dataSetupOptions = parsedOptions.ga;
})(function(videojs) {
return videojs.plugin('ga', function(options) {
var dataSetupOptions, defaultsEventsToTrack, end, error, eventCategory, eventLabel, eventsToTrack, fullscreen, loaded, parsedOptions, pause, percentsAlreadyTracked, percentsPlayedInterval, play, resize, seekEnd, seekStart, seeking, sendbeacon, timeupdate, volumeChange;
if (options == null) {
options = {};
}
}
defaultsEventsToTrack = ['loaded', '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';
eventLabel = options.eventLabel || dataSetupOptions.eventLabel;
percentsAlreadyTracked = [];
seekStart = seekEnd = 0;
seeking = false;
loaded = function() {
if (!eventLabel) {
eventLabel = this.currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i, '');
}
if (__indexOf.call(eventsToTrack, "loadedmetadata") >= 0) {
sendbeacon('loadedmetadata', true);
dataSetupOptions = {};
if (this.options()["data-setup"]) {
parsedOptions = JSON.parse(this.options()["data-setup"]);
if (parsedOptions.ga) {
dataSetupOptions = parsedOptions.ga;
}
}
};
timeupdate = function() {
var currentTime, duration, percent, percentPlayed, _i;
currentTime = Math.round(this.currentTime());
duration = Math.round(this.duration());
percentPlayed = Math.round(currentTime / duration * 100);
for (percent = _i = 0; _i <= 99; percent = _i += percentsPlayedInterval) {
if (percentPlayed >= percent && __indexOf.call(percentsAlreadyTracked, percent) < 0) {
if (__indexOf.call(eventsToTrack, "start") >= 0 && percent === 0 && percentPlayed > 0) {
sendbeacon('start', true);
} else if (__indexOf.call(eventsToTrack, "percentsPlayed") >= 0 && percentPlayed !== 0) {
sendbeacon('percent played', true, percent);
defaultsEventsToTrack = ['loaded', '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';
eventLabel = options.eventLabel || dataSetupOptions.eventLabel;
percentsAlreadyTracked = [];
seekStart = seekEnd = 0;
seeking = false;
loaded = function() {
if (!eventLabel) {
eventLabel = this.currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i, '');
}
if (__indexOf.call(eventsToTrack, "loadedmetadata") >= 0) {
sendbeacon('loadedmetadata', true);
}
};
timeupdate = function() {
var currentTime, duration, percent, percentPlayed, _i;
currentTime = Math.round(this.currentTime());
duration = Math.round(this.duration());
percentPlayed = Math.round(currentTime / duration * 100);
for (percent = _i = 0; _i <= 99; percent = _i += percentsPlayedInterval) {
if (percentPlayed >= percent && __indexOf.call(percentsAlreadyTracked, percent) < 0) {
if (__indexOf.call(eventsToTrack, "start") >= 0 && percent === 0 && percentPlayed > 0) {
sendbeacon('start', true);
} else if (__indexOf.call(eventsToTrack, "percentsPlayed") >= 0 && percentPlayed !== 0) {
sendbeacon('percent played', true, percent);
}
if (percentPlayed > 0) {
percentsAlreadyTracked.push(percent);
}
}
if (percentPlayed > 0) {
percentsAlreadyTracked.push(percent);
}
if (__indexOf.call(eventsToTrack, "seek") >= 0) {
seekStart = seekEnd;
seekEnd = currentTime;
if (Math.abs(seekStart - seekEnd) > 1) {
seeking = true;
sendbeacon('seek start', false, seekStart);
sendbeacon('seek end', false, seekEnd);
}
}
}
if (__indexOf.call(eventsToTrack, "seek") >= 0) {
seekStart = seekEnd;
seekEnd = currentTime;
if (Math.abs(seekStart - seekEnd) > 1) {
seeking = true;
sendbeacon('seek start', false, seekStart);
sendbeacon('seek end', false, seekEnd);
};
end = function() {
sendbeacon('end', true);
};
play = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
sendbeacon('play', true, currentTime);
seeking = false;
};
pause = function() {
var currentTime, duration;
currentTime = Math.round(this.currentTime());
duration = Math.round(this.duration());
if (currentTime !== duration && !seeking) {
sendbeacon('pause', false, currentTime);
}
}
};
end = function() {
sendbeacon('end', true);
};
play = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
sendbeacon('play', true, currentTime);
seeking = false;
};
pause = function() {
var currentTime, duration;
currentTime = Math.round(this.currentTime());
duration = Math.round(this.duration());
if (currentTime !== duration && !seeking) {
sendbeacon('pause', false, currentTime);
}
};
volumeChange = function() {
var volume;
volume = this.muted() === true ? 0 : this.volume();
sendbeacon('volume change', false, volume);
};
resize = function() {
sendbeacon('resize - ' + this.width() + "*" + this.height(), true);
};
error = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
sendbeacon('error', true, currentTime);
};
fullscreen = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
if ((typeof this.isFullscreen === "function" ? this.isFullscreen() : void 0) || (typeof this.isFullScreen === "function" ? this.isFullScreen() : void 0)) {
sendbeacon('enter fullscreen', false, currentTime);
} else {
sendbeacon('exit fullscreen', false, currentTime);
}
};
sendbeacon = function(action, nonInteraction, value) {
if (window.ga) {
ga('send', 'event', {
'eventCategory': eventCategory,
'eventAction': action,
'eventLabel': eventLabel,
'eventValue': value,
'nonInteraction': nonInteraction
});
} else if (window._gaq) {
_gaq.push(['_trackEvent', eventCategory, action, eventLabel, value, nonInteraction]);
} else {
console.log("Google Analytics not detected");
}
};
this.ready(function() {
this.on("loadedmetadata", loaded);
this.on("timeupdate", timeupdate);
if (__indexOf.call(eventsToTrack, "end") >= 0) {
this.on("ended", end);
}
if (__indexOf.call(eventsToTrack, "play") >= 0) {
this.on("play", play);
}
if (__indexOf.call(eventsToTrack, "pause") >= 0) {
this.on("pause", pause);
}
if (__indexOf.call(eventsToTrack, "volumeChange") >= 0) {
this.on("volumechange", volumeChange);
}
if (__indexOf.call(eventsToTrack, "resize") >= 0) {
this.on("resize", resize);
}
if (__indexOf.call(eventsToTrack, "error") >= 0) {
this.on("error", error);
}
if (__indexOf.call(eventsToTrack, "fullscreen") >= 0) {
return this.on("fullscreenchange", fullscreen);
}
};
volumeChange = function() {
var volume;
volume = this.muted() === true ? 0 : this.volume();
sendbeacon('volume change', false, volume);
};
resize = function() {
sendbeacon('resize - ' + this.width() + "*" + this.height(), true);
};
error = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
sendbeacon('error', true, currentTime);
};
fullscreen = function() {
var currentTime;
currentTime = Math.round(this.currentTime());
if ((typeof this.isFullscreen === "function" ? this.isFullscreen() : void 0) || (typeof this.isFullScreen === "function" ? this.isFullScreen() : void 0)) {
sendbeacon('enter fullscreen', false, currentTime);
} else {
sendbeacon('exit fullscreen', false, currentTime);
}
};
sendbeacon = function(action, nonInteraction, value) {
if (window.ga) {
ga('send', 'event', {
'eventCategory': eventCategory,
'eventAction': action,
'eventLabel': eventLabel,
'eventValue': value,
'nonInteraction': nonInteraction
});
} else if (window._gaq) {
_gaq.push(['_trackEvent', eventCategory, action, eventLabel, value, nonInteraction]);
} else {
console.log("Google Analytics not detected");
}
};
this.ready(function() {
this.on("loadedmetadata", loaded);
this.on("timeupdate", timeupdate);
if (__indexOf.call(eventsToTrack, "end") >= 0) {
this.on("ended", end);
}
if (__indexOf.call(eventsToTrack, "play") >= 0) {
this.on("play", play);
}
if (__indexOf.call(eventsToTrack, "pause") >= 0) {
this.on("pause", pause);
}
if (__indexOf.call(eventsToTrack, "volumeChange") >= 0) {
this.on("volumechange", volumeChange);
}
if (__indexOf.call(eventsToTrack, "resize") >= 0) {
this.on("resize", resize);
}
if (__indexOf.call(eventsToTrack, "error") >= 0) {
this.on("error", error);
}
if (__indexOf.call(eventsToTrack, "fullscreen") >= 0) {
return this.on("fullscreenchange", fullscreen);
}
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions dist/videojs.ga.min.js

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

Loading