Created
October 23, 2014 15:22
-
-
Save cmaas/3fccc84a3546fcd16cf9 to your computer and use it in GitHub Desktop.
A simple Piwik tracking plugin for your Impact.js games.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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