Skip to content
Permalink
Browse files

Analytics support

  • Loading branch information...
Depado committed Jun 4, 2018
1 parent 36f77ac commit f4cb8b8c2e7d8958ae23c3118f94056d8668de9d
Showing with 29 additions and 0 deletions.
  1. +13 −0 README.md
  2. +2 −0 cmd/serve.go
  3. +9 −0 templates/analytics.tmpl
  4. +1 −0 templates/index.tmpl
  5. +1 −0 templates/post.tmpl
  6. +3 −0 views/views.go
@@ -87,6 +87,9 @@ server:
host: 127.0.0.1
port: 8006
debug: true
analytics:
enabled: true
tag: xx-xxxxx-xxx
blog:
title: Depado's Blog
description: A simple blog from a developer who does things. Powered by smallblog.
@@ -158,6 +161,16 @@ In this section you can customize the global author. If you fill this, smallblog
will know that every article that doesn't have author information was written
by this author. This will also be displayed on the front page (article list).

### analytics

Configuration for Google Analytics. Other types or platforms will be supported
but for now only GA can be enabled.

| Field | Description | Default |
|-----------|--------------------------------------------------------|-----------|
| `enabled` | Whether or not the Google Analytics feature is enabled | - |
| `tag` | Google Analytics tag to use | - |

### Gitalk

Please see the documentation of [gitalk](https://github.com/gitalk/gitalk) to
@@ -24,6 +24,8 @@ func init() {
serve.Flags().Bool("server.tls", false, "whether https is activated for the domain")

// Gitalk
serve.Flags().Bool("analytics.enabled", false, "enable Google Analytics feature")
serve.Flags().String("analytics.tag", "", "tag for the Google Analytics feature")
serve.Flags().Bool("gitalk.enabled", false, "enable the gitalk feature")
serve.Flags().String("gitalk.client_id", "", "client ID of the gitalk app")
serve.Flags().String("gitalk.client_secret", "", "client secret of the gitalk app")
@@ -0,0 +1,9 @@
{{ define "analytics" }}
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .tag }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ .tag }}');
</script>
{{ end }}
@@ -10,6 +10,7 @@
<link rel="icon" href="/static/favicon.gif">
<script defer src="https://use.fontawesome.com/releases/v5.0.9/js/all.js" integrity="sha384-8iPTk2s/jMVj81dnzb/iFR2sdA7u06vHJyyLlAd4snFpCl/SnyUjRrbdJsw1pGIl" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ if .analytics.enabled }}{{ template "analytics" .analytics }}{{ end }}
</head>

<body>
@@ -15,6 +15,7 @@
<link rel="icon" href="/static/favicon.gif">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{ if .extra_style }}<style>{{ .extra_style }}</style>{{ end }}
{{ if .analytics.enabled }}{{ template "analytics" .analytics }}{{ end }}
</head>

<body>
@@ -38,6 +38,7 @@ func PostsByTag(c *gin.Context) {
"title": viper.GetString("blog.title"),
"description": viper.GetString("blog.description"),
"extra": template.HTML(fmt.Sprintf(`Posts tagged with <span class="home-sm-tag">%s</span>`, tag)),
"analytics": gin.H{"tag": viper.GetString("analytics.tag"), "enabled": viper.GetBool("analytics.enabled")},
"author": models.GetGlobalAuthor(),
}
c.HTML(http.StatusOK, "index.tmpl", data)
@@ -53,6 +54,7 @@ func Post(c *gin.Context) {
"post": page,
"gitalk": models.GetGitalk(),
"extra_style": models.GlobCSS,
"analytics": gin.H{"tag": viper.GetString("analytics.tag"), "enabled": viper.GetBool("analytics.enabled")},
"share": viper.GetBool("blog.share"),
"share_url": page.GetShare(),
}
@@ -78,6 +80,7 @@ func Index(c *gin.Context) {
"posts": models.SPages,
"title": viper.GetString("blog.title"),
"description": viper.GetString("blog.description"),
"analytics": gin.H{"tag": viper.GetString("analytics.tag"), "enabled": viper.GetBool("analytics.enabled")},
"author": models.GetGlobalAuthor(),
}
c.HTML(http.StatusOK, "index.tmpl", data)

0 comments on commit f4cb8b8

Please sign in to comment.
You can’t perform that action at this time.