Skip to content

Commit

Permalink
Merge pull request #16 from jakiestfu/master
Browse files Browse the repository at this point in the history
Optional logging and expose sendbeacon
  • Loading branch information
mickey committed Feb 6, 2015
2 parents db2d6f0 + a07ea50 commit 9ee5803
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```

Expand Down Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions dist/videojs.ga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* videojs-ga - v0.4.1 - 2014-06-06
* Copyright (c) 2014 Michael Bensoussan
* videojs-ga - v0.4.2 - 2015-02-06
* Copyright (c) 2015 Michael Bensoussan
* Licensed MIT
*/
(function() {
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
};
Expand Down Expand Up @@ -140,6 +141,9 @@
return this.on("fullscreenchange", fullscreen);
}
});
return {
'sendbeacon': sendbeacon
};
});

}).call(this);
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videojs-ga",
"version": "0.4.1",
"version": "0.4.2",
"license": "MIT",
"author": {
"name": "Michael Bensoussan",
Expand All @@ -16,4 +16,4 @@
"grunt-banner": "~0.2.2",
"grunt": "~0.4.1"
}
}
}
8 changes: 6 additions & 2 deletions src/videojs.ga.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit 9ee5803

Please sign in to comment.