mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Add yandex metrica tag
This commit is contained in:
@@ -52,7 +52,7 @@ func main() {
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
templateFuncs := &templates.Funcs{Version: Version}
|
templateFuncs := &templates.Funcs{Version: Version, Site: config.Site}
|
||||||
err = templates.Load(templateFuncs)
|
err = templates.Load(templateFuncs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ type Content struct {
|
|||||||
PostsPerPage int `mapstructure:"postsPerPage"`
|
PostsPerPage int `mapstructure:"postsPerPage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Site struct {
|
||||||
|
YandexKey string `mapstructure:"yandexKey"`
|
||||||
|
}
|
||||||
|
|
||||||
// Config contains application configuration
|
// Config contains application configuration
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Verbose string `mapstructure:"verbose"`
|
Verbose string `mapstructure:"verbose"`
|
||||||
@@ -30,6 +34,7 @@ type Config struct {
|
|||||||
Addr string `mapstructure:"addr"`
|
Addr string `mapstructure:"addr"`
|
||||||
Unix string `mapstructure:"unix"`
|
Unix string `mapstructure:"unix"`
|
||||||
Content Content `mapstructure:"content"`
|
Content Content `mapstructure:"content"`
|
||||||
|
Site Site `mapstructure:"site"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize default values on app-start
|
// initialize default values on app-start
|
||||||
@@ -50,6 +55,8 @@ func init() {
|
|||||||
pflag.String("content.pinned", "contact", "pinned page slug")
|
pflag.String("content.pinned", "contact", "pinned page slug")
|
||||||
pflag.Int("content.postsPerPage", 5, "amount of posts per page")
|
pflag.Int("content.postsPerPage", 5, "amount of posts per page")
|
||||||
|
|
||||||
|
pflag.String("site.yandexKey", "", "yandex analytics key")
|
||||||
|
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
|
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{{ with $yk := getYaKey }}
|
||||||
|
{{ if $yk }}
|
||||||
|
<!-- Yandex.Metrika counter -->
|
||||||
|
<script type="text/javascript" >
|
||||||
|
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||||
|
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
||||||
|
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
|
||||||
|
|
||||||
|
ym({{ $yk }}, "init", {
|
||||||
|
clickmap:true,
|
||||||
|
trackLinks:true,
|
||||||
|
accurateTrackBounce:true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<noscript><div><img src="https://mc.yandex.ru/watch/{{ $yk }}" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||||
|
<!-- /Yandex.Metrika counter -->
|
||||||
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
@@ -4,10 +4,13 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Funcs struct {
|
type Funcs struct {
|
||||||
Version string
|
Version string
|
||||||
|
Site config.Site
|
||||||
|
|
||||||
compiledJSAppURL string
|
compiledJSAppURL string
|
||||||
|
|
||||||
@@ -54,6 +57,10 @@ func (f *Funcs) getBlogURL() string {
|
|||||||
return URLBlog
|
return URLBlog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Funcs) getYaKey() string {
|
||||||
|
return f.Site.YandexKey
|
||||||
|
}
|
||||||
|
|
||||||
// Use returns a func map with template helpers functions
|
// Use returns a func map with template helpers functions
|
||||||
func (f *Funcs) Use() template.FuncMap {
|
func (f *Funcs) Use() template.FuncMap {
|
||||||
return template.FuncMap{
|
return template.FuncMap{
|
||||||
@@ -62,5 +69,6 @@ func (f *Funcs) Use() template.FuncMap {
|
|||||||
"getJSAppURL": f.getJSAppURL,
|
"getJSAppURL": f.getJSAppURL,
|
||||||
"getIndexURL": f.getIndexURL,
|
"getIndexURL": f.getIndexURL,
|
||||||
"getBlogURL": f.getBlogURL,
|
"getBlogURL": f.getBlogURL,
|
||||||
|
"getYaKey": f.getYaKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,4 +6,6 @@
|
|||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
|
|
||||||
<script type="text/javascript" src="{{ getJSAppURL }}" async></script>
|
<script type="text/javascript" src="{{ getJSAppURL }}" async></script>
|
||||||
|
|
||||||
|
{{ template "analytics.go.tmpl" . }}
|
||||||
</head>
|
</head>
|
||||||
@@ -18,6 +18,7 @@ import (
|
|||||||
//go:embed index.go.tmpl
|
//go:embed index.go.tmpl
|
||||||
//go:embed menu.go.tmpl
|
//go:embed menu.go.tmpl
|
||||||
//go:embed post.go.tmpl
|
//go:embed post.go.tmpl
|
||||||
|
//go:embed analytics.go.tmpl
|
||||||
var content embed.FS
|
var content embed.FS
|
||||||
|
|
||||||
// List of compiled go-templates
|
// List of compiled go-templates
|
||||||
|
|||||||
Reference in New Issue
Block a user