From 661e9b5ded9f5025c72444a4d64038b7caf8e5d0 Mon Sep 17 00:00:00 2001 From: Jacob Kelley Date: Fri, 6 Feb 2015 11:49:15 -0800 Subject: [PATCH 1/4] Adding debug option check and returning sendbeacon --- src/videojs.ga.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/videojs.ga.coffee b/src/videojs.ga.coffee index c8dca7a..495d4bb 100644 --- a/src/videojs.ga.coffee +++ b/src/videojs.ga.coffee @@ -25,6 +25,9 @@ videojs.plugin 'ga', (options = {}) -> # if you didn't specify a name, it will be 'guessed' from the video src after metadatas are loaded eventLabel = options.eventLabel || dataSetupOptions.eventLabel + # if debug isn't specified + options.debug = options.debug || false + # init a few variables percentsAlreadyTracked = [] seekStart = seekEnd = 0 @@ -118,7 +121,7 @@ videojs.plugin 'ga', (options = {}) -> 'nonInteraction' : nonInteraction else if window._gaq _gaq.push(['_trackEvent', eventCategory, action, eventLabel, value, nonInteraction]) - else + else if options.debug console.log("Google Analytics not detected") return @@ -132,4 +135,5 @@ videojs.plugin 'ga', (options = {}) -> @on("resize", resize) if "resize" in eventsToTrack @on("error", error) if "error" in eventsToTrack @on("fullscreenchange", fullscreen) if "fullscreen" in eventsToTrack - return + + return 'sendbeacon': sendbeacon From 2b711cbbd637bf5aba2c199e618386b5572c9342 Mon Sep 17 00:00:00 2001 From: Jacob Kelley Date: Fri, 6 Feb 2015 11:49:22 -0800 Subject: [PATCH 2/4] dist files --- dist/videojs.ga.js | 10 +++++++--- dist/videojs.ga.min.js | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dist/videojs.ga.js b/dist/videojs.ga.js index 0a6b607..5da8936 100644 --- a/dist/videojs.ga.js +++ b/dist/videojs.ga.js @@ -1,6 +1,6 @@ /* -* videojs-ga - v0.4.1 - 2014-06-06 -* Copyright (c) 2014 Michael Bensoussan +* videojs-ga - v0.4.1 - 2015-02-06 +* Copyright (c) 2015 Michael Bensoussan * Licensed MIT */ (function() { @@ -23,6 +23,7 @@ percentsPlayedInterval = options.percentsPlayedInterval || dataSetupOptions.percentsPlayedInterval || 10; eventCategory = options.eventCategory || dataSetupOptions.eventCategory || 'Video'; eventLabel = options.eventLabel || dataSetupOptions.eventLabel; + options.debug = options.debug || false; percentsAlreadyTracked = []; seekStart = seekEnd = 0; seeking = false; @@ -111,7 +112,7 @@ }); } else if (window._gaq) { _gaq.push(['_trackEvent', eventCategory, action, eventLabel, value, nonInteraction]); - } else { + } else if (options.debug) { console.log("Google Analytics not detected"); } }; @@ -140,6 +141,9 @@ return this.on("fullscreenchange", fullscreen); } }); + return { + 'sendbeacon': sendbeacon + }; }); }).call(this); diff --git a/dist/videojs.ga.min.js b/dist/videojs.ga.min.js index d4ff524..8929d19 100644 --- a/dist/videojs.ga.min.js +++ b/dist/videojs.ga.min.js @@ -1,6 +1,6 @@ /* -* videojs-ga - v0.4.1 - 2014-06-06 -* Copyright (c) 2014 Michael Bensoussan +* videojs-ga - v0.4.1 - 2015-02-06 +* Copyright (c) 2015 Michael Bensoussan * Licensed MIT */ -(function(){var a=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};videojs.plugin("ga",function(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;null==b&&(b={}),c={},this.options()["data-setup"]&&(l=JSON.parse(this.options()["data-setup"]),l.ga&&(c=l.ga)),d=["loaded","percentsPlayed","start","end","seek","play","pause","resize","volumeChange","error","fullscreen"],i=b.eventsToTrack||c.eventsToTrack||d,o=b.percentsPlayedInterval||c.percentsPlayedInterval||10,g=b.eventCategory||c.eventCategory||"Video",h=b.eventLabel||c.eventLabel,n=[],s=r=0,t=!1,k=function(){h||(h=this.currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i,"")),a.call(i,"loadedmetadata")>=0&&u("loadedmetadata",!0)},v=function(){var b,c,d,e,f;for(b=Math.round(this.currentTime()),c=Math.round(this.duration()),e=Math.round(b/c*100),d=f=0;99>=f;d=f+=o)e>=d&&a.call(n,d)<0&&(a.call(i,"start")>=0&&0===d&&e>0?u("start",!0):a.call(i,"percentsPlayed")>=0&&0!==e&&u("percent played",!0,d),e>0&&n.push(d));a.call(i,"seek")>=0&&(s=r,r=b,Math.abs(s-r)>1&&(t=!0,u("seek start",!1,s),u("seek end",!1,r)))},e=function(){u("end",!0)},p=function(){var a;a=Math.round(this.currentTime()),u("play",!0,a),t=!1},m=function(){var a,b;a=Math.round(this.currentTime()),b=Math.round(this.duration()),a===b||t||u("pause",!1,a)},w=function(){var a;a=this.muted()===!0?0:this.volume(),u("volume change",!1,a)},q=function(){u("resize - "+this.width()+"*"+this.height(),!0)},f=function(){var a;a=Math.round(this.currentTime()),u("error",!0,a)},j=function(){var a;a=Math.round(this.currentTime()),("function"==typeof this.isFullscreen?this.isFullscreen():void 0)||("function"==typeof this.isFullScreen?this.isFullScreen():void 0)?u("enter fullscreen",!1,a):u("exit fullscreen",!1,a)},u=function(a,b,c){window.ga?ga("send","event",{eventCategory:g,eventAction:a,eventLabel:h,eventValue:c,nonInteraction:b}):window._gaq?_gaq.push(["_trackEvent",g,a,h,c,b]):console.log("Google Analytics not detected")},this.ready(function(){return this.on("loadedmetadata",k),this.on("timeupdate",v),a.call(i,"end")>=0&&this.on("ended",e),a.call(i,"play")>=0&&this.on("play",p),a.call(i,"pause")>=0&&this.on("pause",m),a.call(i,"volumeChange")>=0&&this.on("volumechange",w),a.call(i,"resize")>=0&&this.on("resize",q),a.call(i,"error")>=0&&this.on("error",f),a.call(i,"fullscreen")>=0?this.on("fullscreenchange",j):void 0})})}).call(this); \ No newline at end of file +(function(){var a=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};videojs.plugin("ga",function(b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;return null==b&&(b={}),c={},this.options()["data-setup"]&&(l=JSON.parse(this.options()["data-setup"]),l.ga&&(c=l.ga)),d=["loaded","percentsPlayed","start","end","seek","play","pause","resize","volumeChange","error","fullscreen"],i=b.eventsToTrack||c.eventsToTrack||d,o=b.percentsPlayedInterval||c.percentsPlayedInterval||10,g=b.eventCategory||c.eventCategory||"Video",h=b.eventLabel||c.eventLabel,b.debug=b.debug||!1,n=[],s=r=0,t=!1,k=function(){h||(h=this.currentSrc().split("/").slice(-1)[0].replace(/\.(\w{3,4})(\?.*)?$/i,"")),a.call(i,"loadedmetadata")>=0&&u("loadedmetadata",!0)},v=function(){var b,c,d,e,f;for(b=Math.round(this.currentTime()),c=Math.round(this.duration()),e=Math.round(b/c*100),d=f=0;99>=f;d=f+=o)e>=d&&a.call(n,d)<0&&(a.call(i,"start")>=0&&0===d&&e>0?u("start",!0):a.call(i,"percentsPlayed")>=0&&0!==e&&u("percent played",!0,d),e>0&&n.push(d));a.call(i,"seek")>=0&&(s=r,r=b,Math.abs(s-r)>1&&(t=!0,u("seek start",!1,s),u("seek end",!1,r)))},e=function(){u("end",!0)},p=function(){var a;a=Math.round(this.currentTime()),u("play",!0,a),t=!1},m=function(){var a,b;a=Math.round(this.currentTime()),b=Math.round(this.duration()),a===b||t||u("pause",!1,a)},w=function(){var a;a=this.muted()===!0?0:this.volume(),u("volume change",!1,a)},q=function(){u("resize - "+this.width()+"*"+this.height(),!0)},f=function(){var a;a=Math.round(this.currentTime()),u("error",!0,a)},j=function(){var a;a=Math.round(this.currentTime()),("function"==typeof this.isFullscreen?this.isFullscreen():void 0)||("function"==typeof this.isFullScreen?this.isFullScreen():void 0)?u("enter fullscreen",!1,a):u("exit fullscreen",!1,a)},u=function(a,c,d){window.ga?ga("send","event",{eventCategory:g,eventAction:a,eventLabel:h,eventValue:d,nonInteraction:c}):window._gaq?_gaq.push(["_trackEvent",g,a,h,d,c]):b.debug&&console.log("Google Analytics not detected")},this.ready(function(){return this.on("loadedmetadata",k),this.on("timeupdate",v),a.call(i,"end")>=0&&this.on("ended",e),a.call(i,"play")>=0&&this.on("play",p),a.call(i,"pause")>=0&&this.on("pause",m),a.call(i,"volumeChange")>=0&&this.on("volumechange",w),a.call(i,"resize")>=0&&this.on("resize",q),a.call(i,"error")>=0&&this.on("error",f),a.call(i,"fullscreen")>=0?this.on("fullscreenchange",j):void 0}),{sendbeacon:u}})}).call(this); \ No newline at end of file From 97c8567a1cade47378372c34d770133c6348ac42 Mon Sep 17 00:00:00 2001 From: Jacob Kelley Date: Fri, 6 Feb 2015 11:49:58 -0800 Subject: [PATCH 3/4] Upping version --- dist/videojs.ga.js | 2 +- dist/videojs.ga.min.js | 2 +- package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/videojs.ga.js b/dist/videojs.ga.js index 5da8936..dbda0a2 100644 --- a/dist/videojs.ga.js +++ b/dist/videojs.ga.js @@ -1,5 +1,5 @@ /* -* videojs-ga - v0.4.1 - 2015-02-06 +* videojs-ga - v0.4.2 - 2015-02-06 * Copyright (c) 2015 Michael Bensoussan * Licensed MIT */ diff --git a/dist/videojs.ga.min.js b/dist/videojs.ga.min.js index 8929d19..b57c784 100644 --- a/dist/videojs.ga.min.js +++ b/dist/videojs.ga.min.js @@ -1,5 +1,5 @@ /* -* videojs-ga - v0.4.1 - 2015-02-06 +* videojs-ga - v0.4.2 - 2015-02-06 * Copyright (c) 2015 Michael Bensoussan * Licensed MIT */ diff --git a/package.json b/package.json index 264a221..9133450 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "videojs-ga", - "version": "0.4.1", + "version": "0.4.2", "license": "MIT", "author": { "name": "Michael Bensoussan", @@ -16,4 +16,4 @@ "grunt-banner": "~0.2.2", "grunt": "~0.4.1" } -} \ No newline at end of file +} From a07ea509c0935d60880508ee45db86c61ee80ba7 Mon Sep 17 00:00:00 2001 From: Jacob Kelley Date: Fri, 6 Feb 2015 11:53:39 -0800 Subject: [PATCH 4/4] readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e1a4db..a99309e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,8 @@ You can provide options to the plugin either by passing them in the javascript o ```javascript player.ga({ - 'eventsToTrack': ['fullscreen', 'resize'] + 'eventsToTrack': ['fullscreen', 'resize'], + 'debug': true }); ``` @@ -64,6 +65,11 @@ Most of the events are selft explanatory, here's the ones that may need more det This options goes with the ```percentsPlayed``` event. Every ```percentsPlayedInterval``` percents an event will be sent to GA. **default:** 10 +####debug + +If set to false, console logs will be ommited +**default:** ```false``` + #### ga.js and analytics.js This plugin supports the ga.js and the newer analytics.js Google Analytics libraries. It autodetects the library you use.