diff --git a/src/engine/analytics.js b/src/engine/analytics.js new file mode 100644 index 00000000..13c9ce9c --- /dev/null +++ b/src/engine/analytics.js @@ -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 = ''; + +}); \ No newline at end of file diff --git a/src/engine/core.js b/src/engine/core.js index dd0ee41b..5f597252 100755 --- a/src/engine/core.js +++ b/src/engine/core.js @@ -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; @@ -698,7 +699,8 @@ game.module( 'engine.storage', 'engine.tween', 'engine.scene', - 'engine.pool' + 'engine.pool', + 'engine.analytics' ) .body(function(){ // ready to start engine