Commit 3d37c9c9 by Torkel Ödegaard

feat(tagmanager): support to add google tagmanager id, closes #2569

parent 7072af7c
...@@ -9,7 +9,7 @@ watch_dirs = [ ...@@ -9,7 +9,7 @@ watch_dirs = [
"$WORKDIR/public/views", "$WORKDIR/public/views",
"$WORKDIR/conf", "$WORKDIR/conf",
] ]
watch_exts = [".go", ".ini", ".toml"] watch_exts = [".go", ".ini", ".toml", ".html"]
build_delay = 1500 build_delay = 1500
cmds = [ cmds = [
["go", "build", "-o", "./bin/grafana-server"], ["go", "build", "-o", "./bin/grafana-server"],
......
...@@ -98,6 +98,9 @@ reporting_enabled = true ...@@ -98,6 +98,9 @@ reporting_enabled = true
# Google Analytics universal tracking code, only enabled if you specify an id here # Google Analytics universal tracking code, only enabled if you specify an id here
google_analytics_ua_id = google_analytics_ua_id =
# Google Tag Manager ID, only enabled if you specify an id here
google_tag_manager_id =
#################################### Security #################################### #################################### Security ####################################
[security] [security]
# default admin user, created on startup # default admin user, created on startup
......
...@@ -17,6 +17,7 @@ type LoginCommand struct { ...@@ -17,6 +17,7 @@ type LoginCommand struct {
type CurrentUser struct { type CurrentUser struct {
IsSignedIn bool `json:"isSignedIn"` IsSignedIn bool `json:"isSignedIn"`
Id int64 `json:"id"`
Login string `json:"login"` Login string `json:"login"`
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
......
...@@ -13,6 +13,7 @@ func setIndexViewData(c *middleware.Context) error { ...@@ -13,6 +13,7 @@ func setIndexViewData(c *middleware.Context) error {
} }
currentUser := &dtos.CurrentUser{ currentUser := &dtos.CurrentUser{
Id: c.UserId,
IsSignedIn: c.IsSignedIn, IsSignedIn: c.IsSignedIn,
Login: c.Login, Login: c.Login,
Email: c.Email, Email: c.Email,
...@@ -47,6 +48,10 @@ func setIndexViewData(c *middleware.Context) error { ...@@ -47,6 +48,10 @@ func setIndexViewData(c *middleware.Context) error {
c.Data["GoogleAnalyticsId"] = setting.GoogleAnalyticsId c.Data["GoogleAnalyticsId"] = setting.GoogleAnalyticsId
} }
if setting.GoogleTagManagerId != "" {
c.Data["GoogleTagManagerId"] = setting.GoogleTagManagerId
}
return nil return nil
} }
......
...@@ -114,8 +114,9 @@ var ( ...@@ -114,8 +114,9 @@ var (
appliedCommandLineProperties []string appliedCommandLineProperties []string
appliedEnvOverrides []string appliedEnvOverrides []string
ReportingEnabled bool ReportingEnabled bool
GoogleAnalyticsId string GoogleAnalyticsId string
GoogleTagManagerId string
// LDAP // LDAP
LdapEnabled bool LdapEnabled bool
...@@ -415,6 +416,7 @@ func NewConfigContext(args *CommandLineArgs) { ...@@ -415,6 +416,7 @@ func NewConfigContext(args *CommandLineArgs) {
analytics := Cfg.Section("analytics") analytics := Cfg.Section("analytics")
ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true) ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
GoogleAnalyticsId = analytics.Key("google_analytics_ua_id").String() GoogleAnalyticsId = analytics.Key("google_analytics_ua_id").String()
GoogleTagManagerId = analytics.Key("google_tag_manager_id").String()
ldapSec := Cfg.Section("auth.ldap") ldapSec := Cfg.Section("auth.ldap")
LdapEnabled = ldapSec.Key("enabled").MustBool(false) LdapEnabled = ldapSec.Key("enabled").MustBool(false)
......
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
require(['app'], function (app) { require(['app'], function (app) {
app.boot(); app.boot();
}) })
</script> </script>
[[if .GoogleAnalyticsId]] [[if .GoogleAnalyticsId]]
...@@ -71,4 +70,21 @@ ...@@ -71,4 +70,21 @@
</script> </script>
[[end]] [[end]]
[[if .GoogleTagManagerId]]
<script>
dataLayer = [{
'IsSignedIn': '[[.User.IsSignedIn]]',
'Email': '[[.User.Email]]',
'UserId': '[[.User.Id]]',
'OrgId': '[[.User.OrgId]]',
'OrgName': '[[.User.OrgName]]',
}];
</script>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-K2MJ65" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','[[.GoogleTagManagerId]]');</script>
<!-- End Google Tag Manager -->
[[end]]
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment