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

add Piwik-Integration #22

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
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# videojs-ga
# videojs-analytics

Google Analytics plugin for video.js
Google and Piwik Analytics plugin for video.js

## Getting Started
Download [videojs](http://www.videojs.com/) and [videojs.ga](https://github.com/mickey/videojs-ga)
Download [videojs](http://www.videojs.com/) and [videojs-analytics](https://github.com/azine/videojs-analytics)

In your web page:
```html
Expand All @@ -17,7 +17,7 @@ videojs('video', {}, function() {
</script>
```

_Please note that the Google Analytics script must be loaded before the ga plugin_
_Please note that the Google Analytics and/or Piwik script must be loaded before the ga plugin_

## Options

Expand Down Expand Up @@ -70,12 +70,16 @@ This options goes with the ```percentsPlayed``` event. Every ```percentsPlayedIn
If set to false, console logs will be ommited
**default:** ```false```

#### ga.js and analytics.js
#### ga.js, analytics.js and piwik.js

This plugin supports the ga.js and the newer analytics.js Google Analytics libraries. It autodetects the library you use.
This plugin supports the ga.js and the newer analytics.js Google Analytics libraries. It also supports piwik.js.
It autodetects the library you use and if both GoogleAnalytics and Piwik is used by your site, it will log to both systems.


## TODO

- [x] track the engine used (html5/flash) along with the source (ogg, mp4, ...)
- [ ] track the time to download the video
- [ ] refactor source-code, docs and tests to replace references to "GA" with a more general term that makes sense for GoogleAnalytics and for Piwik.


15 changes: 15 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,28 @@
this.ga();
});

/** load GoogleAnalytics */
(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),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','http://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'none' });
ga('send', 'pageview');

/** load piwik */
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var host = window.location.hostname;
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://"+host+"/piwik/";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();

</script>

</body>
Expand Down
7 changes: 6 additions & 1 deletion dist/videojs.ga.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* videojs-ga - v0.4.2 - 2015-02-06
* videojs-ga - v0.4.2 - 2015-09-14
* Copyright (c) 2015 Michael Bensoussan
* Licensed MIT
*/
Expand Down Expand Up @@ -115,6 +115,11 @@
} else if (options.debug) {
console.log("Google Analytics not detected");
}
if (window._paq) {
_paq.push(['trackEvent', eventCategory, action, eventLabel, value]);
} else if (options.debug) {
console.log("Piwik not detected");
}
};
this.ready(function() {
this.on("loadedmetadata", loaded);
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.

6 changes: 6 additions & 0 deletions src/videojs.ga.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ videojs.plugin 'ga', (options = {}) ->
_gaq.push(['_trackEvent', eventCategory, action, eventLabel, value, nonInteraction])
else if options.debug
console.log("Google Analytics not detected")

if window._paq
_paq.push(['trackEvent', eventCategory, action, eventLabel, value])
else if options.debug
console.log("Piwik not detected")

return

@ready ->
Expand Down