diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index 7ce50dcc9..2f2e02fba 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -88,6 +88,9 @@ var (
AppDataPath string
AppWorkPath string
+ // User settings
+ GoogleAnalyticsID string
+
// Server settings
Protocol Scheme
Domain string
@@ -695,6 +698,7 @@ func NewContext() {
sec := Cfg.Section("server")
AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
+ GoogleAnalyticsID = Cfg.Section("").Key("GOOGLE_ANALYTICS_ID").String()
Protocol = HTTP
if sec.Key("PROTOCOL").String() == "https" {
diff --git a/modules/templates/helper.go b/modules/templates/helper.go
index b6c835ad4..88628ef99 100644
--- a/modules/templates/helper.go
+++ b/modules/templates/helper.go
@@ -60,6 +60,9 @@ func NewFuncMap() []template.FuncMap {
"DisableGravatar": func() bool {
return setting.DisableGravatar
},
+ "GoogleAnalyticsID": func() string {
+ return setting.GoogleAnalyticsID
+ },
"ShowFooterTemplateLoadTime": func() bool {
return setting.ShowFooterTemplateLoadTime
},
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index fb9611cb6..276aeba01 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -105,6 +105,17 @@
+{{if .GoogleAnalyticsID}}
+
+
+
+{{end}}
{{if .PageIsUserProfile}}