Skip to content

Commit 123938a

Browse files
committed
google analytics support
1 parent cbec2f8 commit 123938a

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

config.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99

1010
// Config is struct of gena's config
1111
type Config struct {
12-
Title string
13-
Description string
14-
Template string
15-
URL string
16-
Logo string
17-
Github string
18-
Footer string
19-
Content *Content
12+
Title string
13+
Description string
14+
Template string
15+
URL string
16+
Logo string
17+
Github string
18+
Footer string
19+
Content *Content
20+
GoogleAnalytics string `yaml:"google_analytics"`
2021
}
2122

2223
// Content is struct of categories
@@ -48,6 +49,5 @@ func ParseConfig(file string) (*Config, error) {
4849
if err := yaml.Unmarshal(buf, cfg); err != nil {
4950
return nil, err
5051
}
51-
5252
return cfg, nil
5353
}

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ footer: © 2017-2020 WebStack design by Viggo
1717
# 1. webstack (http://webstack.cc)
1818
template: webstack
1919

20+
google_analytics: "G-EXE1PJ8CR2"
21+
2022
content:
2123
categories:
2224
- name: 社区

templates/webstack.tmpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
<title>{{ .Title }}</title>
99
<meta name="keywords" content="{{ .Description }}">
1010
<meta name="description" content="{{ .Description }}">
11+
{{ if .GoogleAnalytics }}
12+
<!-- Global site tag (gtag.js) - Google Analytics -->
13+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ .GoogleAnalytics }}"></script>
14+
<script>
15+
window.dataLayer = window.dataLayer || [];
16+
function gtag(){dataLayer.push(arguments);}
17+
gtag('js', new Date());
18+
gtag('config', '{{ .GoogleAnalytics }}');
19+
</script>
20+
{{ end }}
1121
<link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/x1ah/webstack-assets@master/assets/images/favicon.png">
1222
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Arimo:400,700,400italic">
1323
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/x1ah/webstack-assets@master/assets/css/fonts/linecons/css/linecons.css">
@@ -18,11 +28,6 @@
1828
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/x1ah/webstack-assets@master/assets/css/xenon-skins.css">
1929
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/x1ah/webstack-assets@master/assets/css/nav.css">
2030
<script src="https://cdn.jsdelivr.net/gh/x1ah/webstack-assets@master/assets/js/jquery-1.11.1.min.js"></script>
21-
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
22-
<!--[if lt IE 9]>
23-
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
24-
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
25-
<![endif]-->
2631
<!-- / FB Open Graph -->
2732
<meta property="og:type" content="article">
2833
<meta property="og:url" content="{{ .URL }}">

0 commit comments

Comments
 (0)