Skip to content

Instantly share code, notes, and snippets.

@cmaas
Created October 23, 2014 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmaas/3fccc84a3546fcd16cf9 to your computer and use it in GitHub Desktop.
Save cmaas/3fccc84a3546fcd16cf9 to your computer and use it in GitHub Desktop.
A simple Piwik tracking plugin for your Impact.js games.
/**
* Loosely based on tracking.js for Google Analytics by Jesse Freeman: https://gist.github.com/jessefreeman/7531064
* How to Use:
* - Copy to your lib/plugins folder, require in main.js
*
* - in main.js init():
* this.tracking = new PiwikTracking();
* ig.game.tracking = this.tracking;
*
* - install Piwik tracking code in your index.html like you normally do
*
* - use throughout your entire game like so: ig.game.trackEvent(...);
*/
ig.module(
'plugins.piwik-tracking'
)
.requires(
)
.defines(function() {
PiwikTracking = ig.Class.extend({
debug: false,
init: function() {
},
trackEvent: function(category, name, action, value) {
if (_paq) {
// trackEvent(category, action, [name], [value]), see:
// http://developer.piwik.org/api-reference/tracking-javascript#list-of-all-methods-available-in-the-tracking-api
_paq.push(['trackEvent', category, name, action, value]);
if (this.debug) {
console.log("trackEvent: " + category + " -> " + name + ": " + action + " ("+value+")");
}
}
else {
this.analyticsNotFound();
}
},
analyticsNotFound: function() {
if (this.debug) {
console.log("Piwik Tracker not found.");
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment