@@ -2,6 +2,7 @@ goog.provide('launcher.Application');
22goog . require ( 'launcher.BaseApplication' ) ;
33goog . require ( 'launcher.services.AppList' ) ;
44goog . require ( 'launcher.services.HelpBarItemFactory' ) ;
5+ goog . require ( 'zb.ui.GoogleAnalytics' ) ;
56
67
78
@@ -12,6 +13,7 @@ goog.require('launcher.services.HelpBarItemFactory');
1213launcher . Application = function ( ) {
1314 zb . console . setLevel ( zb . console . Level . LOG | zb . console . Level . ERROR ) ;
1415 this . services = {
16+ ga : null ,
1517 appList : null ,
1618 helpBarItemFactory : null
1719 } ;
@@ -33,6 +35,21 @@ launcher.Application.prototype.canBack = function() {
3335 * @inheritDoc
3436 */
3537launcher . Application . prototype . onReady = function ( ) {
38+ var gaId = '' ;
39+ if ( COMPILED ) {
40+ gaId = launcher . appConfig . googleAnalyticsId ;
41+
42+ this . _layerManager . on ( this . _layerManager . EVENT_TRANSITION_SUCCESS , function ( eventName , transitionData ) {
43+ transitionData = /** @type {zb.LayerManager.TransitionData } */ ( transitionData ) ;
44+ var layer = transitionData . layer ;
45+ var pageName = '/' + / s - ( [ a - z 0 - 9 \- ] + ) $ / i. exec ( layer . getCSSClassName ( ) ) [ 1 ] ;
46+ this . services . ga . sendPageview ( pageName ) ;
47+ } . bind ( this ) ) ;
48+ }
49+
50+ this . services . ga = new zb . ui . GoogleAnalytics ( gaId , this . device , {
51+ analyticsJS : 'analytics.js'
52+ } ) ;
3653 this . services . appList = new launcher . services . AppList ( this . device . storage ) ;
3754 this . services . helpBarItemFactory = new launcher . services . HelpBarItemFactory ;
3855 this . setHomeScene ( 'app-list' ) ;
@@ -45,8 +62,10 @@ launcher.Application.prototype.onReady = function() {
4562launcher . Application . prototype . onStart = function ( ) {
4663 var apps = this . services . appList . getApps ( ) ;
4764 if ( apps . length ) {
65+ this . services . ga . sendEvent ( 'app' , 'start' ) ;
4866 this . home ( ) ;
4967 } else {
68+ this . services . ga . sendEvent ( 'app' , 'first-start' ) ;
5069 this . show ( 'app-add' , { } ) ;
5170 }
5271} ;
@@ -70,6 +89,7 @@ launcher.Application.prototype._appendScreenSizeClass = function() {
7089
7190/**
7291 * @type {{
92+ * ga: zb.ui.GoogleAnalytics,
7393 * appList: launcher.services.AppList,
7494 * helpBarItemFactory: launcher.services.HelpBarItemFactory
7595 * }}
0 commit comments