Skip to content

Commit

Permalink
New: Google Analytics module
Browse files Browse the repository at this point in the history
  • Loading branch information
Eemeli Kelokorpi committed Feb 13, 2014
1 parent a46f2d8 commit 34dd27d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/engine/analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
game.module(
'engine.analytics'
)
.body(function() {

game.Analytics = game.Class.extend({
init: function(id) {
(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','//www.google-analytics.com/analytics.js','ga');

ga('create', id, 'auto');
ga('send', 'pageview');
},

event: function(category, action) {
ga('send', 'event', category, action);
}
});

game.Analytics.id = '';

});
4 changes: 3 additions & 1 deletion src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ var core = {
if(game.Debug && game.Debug.enabled && !navigator.isCocoonJS) this.debug = new game.Debug();
if(game.DebugDraw && game.DebugDraw.enabled) this.debugDraw = new game.DebugDraw();
if(game.Storage.id) this.storage = new game.Storage(game.Storage.id);
if(game.Analytics.id) this.analytics = new game.Analytics(game.Analytics.id);

this.ready = true;

Expand Down Expand Up @@ -698,7 +699,8 @@ game.module(
'engine.storage',
'engine.tween',
'engine.scene',
'engine.pool'
'engine.pool',
'engine.analytics'
)
.body(function(){
// ready to start engine
Expand Down

0 comments on commit 34dd27d

Please sign in to comment.