diff --git a/conf/defaults.ini b/conf/defaults.ini index 8d724c737d8..d372c825f53 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1,12 +1,6 @@ app_name = Grafana app_mode = production -# Report anonymous usage counters to stats.grafana.org (https). -# No ip addresses are being tracked, only simple counters to track -# running instances, dashboard and error counts. It is very helpful to us. -# Change this option to false to disable reporting. -reporting-enabled = true - [server] ; protocol (http or https) protocol = http @@ -21,11 +15,21 @@ root_url = %(protocol)s://%(domain)s:%(http_port)s/ router_logging = false ; the path relative to the binary where the static (html/js/css) files are placed static_root_path = public +; enable gzip enable_gzip = false -; if https protocol +; https certs & key file cert_file = cert_key = +[analytics] +# Server reporting, sends usage counters to stats.grafana.org (https). +# No ip addresses are being tracked, only simple counters to track +# running instances, dashboard and error counts. It is very helpful to us. +# Change this option to false to disable reporting. +reporting_enabled = true +; Google Analytics universal tracking code, only enabled if you specify an id here +google_analytics_ua_id = + [database] ; Either "mysql", "postgres" or "sqlite3", it's your choice type = sqlite3 diff --git a/conf/sample.ini b/conf/sample.ini index 1e91418826a..3d4f6cf8e57 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -5,12 +5,6 @@ app_mode = production -# Report anonymous usage counters to stats.grafana.org (https). -# No ip addresses are being tracked, only simple counters to track -# running instances, dashboard and error counts. It is very helpful to us. -# Change this option to false to disable reporting. -reporting-enabled = true - [server] ; protocol (http or https) protocol = http @@ -27,6 +21,15 @@ router_logging = false static_root_path = public enable_gzip = false +[analytics] +# Server reporting, sends usage counters to stats.grafana.org (https). +# No ip addresses are being tracked, only simple counters to track +# running instances, dashboard and error counts. It is very helpful to us. +# Change this option to false to disable reporting. +reporting_enabled = true +; Google Analytics universal tracking code, only enabled if you specify an id here +google_analytics_ua_id = + [database] ; Either "mysql", "postgres" or "sqlite3", it's your choice type = sqlite3 diff --git a/pkg/api/index.go b/pkg/api/index.go index 4af66f18133..ceafc37b7c1 100644 --- a/pkg/api/index.go +++ b/pkg/api/index.go @@ -33,6 +33,10 @@ func setIndexViewData(c *middleware.Context) error { c.Data["AppUrl"] = setting.AppUrl c.Data["AppSubUrl"] = setting.AppSubUrl + if setting.GoogleAnalyticsId != "" { + c.Data["GoogleAnalyticsId"] = setting.GoogleAnalyticsId + } + return nil } diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index defa8311e8c..87d943cdd5c 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -97,7 +97,8 @@ var ( configFiles []string - ReportingEnabled bool + ReportingEnabled bool + GoogleAnalyticsId string ) func init() { @@ -235,7 +236,9 @@ func NewConfigContext(config string) { ImagesDir = "data/png" PhantomDir = "vendor/phantomjs" - ReportingEnabled = Cfg.Section("").Key("reporting-enabled").MustBool(true) + analytics := Cfg.Section("analytics") + ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true) + GoogleAnalyticsId = analytics.Key("google_analytics_ua_id").String() readSessionConfig() } diff --git a/src/app/services/all.js b/src/app/services/all.js index 70b363d074d..da1dfebd06a 100644 --- a/src/app/services/all.js +++ b/src/app/services/all.js @@ -5,6 +5,7 @@ define([ './contextSrv', './timer', './keyboardManager', + './analytics', './popoverSrv', './backendSrv', ], diff --git a/src/app/services/analytics.js b/src/app/services/analytics.js new file mode 100644 index 00000000000..4bb7f0c79db --- /dev/null +++ b/src/app/services/analytics.js @@ -0,0 +1,28 @@ +define([ + 'angular', +], +function(angular) { + 'use strict'; + + var module = angular.module('grafana.services'); + module.service('googleAnalyticsSrv', function($rootScope, $location) { + + var first = true; + + this.init = function() { + $rootScope.$on('$viewContentLoaded', function() { + // skip first + if (first) { + first = false; + return; + } + window.ga('send', 'pageview', { page: $location.url() }); + }); + }; + + }).run(function(googleAnalyticsSrv) { + if (window.ga) { + googleAnalyticsSrv.init(); + } + }); +}); diff --git a/src/views/index.html b/src/views/index.html index fd92bccd0d5..29a31d1eda3 100644 --- a/src/views/index.html +++ b/src/views/index.html @@ -59,5 +59,19 @@ require(['app'], function (app) { app.boot(); }) + + + [[if .GoogleAnalyticsId]] + + [[end]] +