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:
@@ -23,6 +23,10 @@ type Content struct {
|
||||
PostsPerPage int `mapstructure:"postsPerPage"`
|
||||
}
|
||||
|
||||
type Site struct {
|
||||
YandexKey string `mapstructure:"yandexKey"`
|
||||
}
|
||||
|
||||
// Config contains application configuration
|
||||
type Config struct {
|
||||
Verbose string `mapstructure:"verbose"`
|
||||
@@ -30,6 +34,7 @@ type Config struct {
|
||||
Addr string `mapstructure:"addr"`
|
||||
Unix string `mapstructure:"unix"`
|
||||
Content Content `mapstructure:"content"`
|
||||
Site Site `mapstructure:"site"`
|
||||
}
|
||||
|
||||
// initialize default values on app-start
|
||||
@@ -50,6 +55,8 @@ func init() {
|
||||
pflag.String("content.pinned", "contact", "pinned page slug")
|
||||
pflag.Int("content.postsPerPage", 5, "amount of posts per page")
|
||||
|
||||
pflag.String("site.yandexKey", "", "yandex analytics key")
|
||||
|
||||
pflag.Parse()
|
||||
|
||||
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"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
||||
)
|
||||
|
||||
type Funcs struct {
|
||||
Version string
|
||||
Site config.Site
|
||||
|
||||
compiledJSAppURL string
|
||||
|
||||
@@ -54,6 +57,10 @@ func (f *Funcs) getBlogURL() string {
|
||||
return URLBlog
|
||||
}
|
||||
|
||||
func (f *Funcs) getYaKey() string {
|
||||
return f.Site.YandexKey
|
||||
}
|
||||
|
||||
// Use returns a func map with template helpers functions
|
||||
func (f *Funcs) Use() template.FuncMap {
|
||||
return template.FuncMap{
|
||||
@@ -62,5 +69,6 @@ func (f *Funcs) Use() template.FuncMap {
|
||||
"getJSAppURL": f.getJSAppURL,
|
||||
"getIndexURL": f.getIndexURL,
|
||||
"getBlogURL": f.getBlogURL,
|
||||
"getYaKey": f.getYaKey,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,6 @@
|
||||
<title>{{ .Title }}</title>
|
||||
|
||||
<script type="text/javascript" src="{{ getJSAppURL }}" async></script>
|
||||
|
||||
{{ template "analytics.go.tmpl" . }}
|
||||
</head>
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
//go:embed index.go.tmpl
|
||||
//go:embed menu.go.tmpl
|
||||
//go:embed post.go.tmpl
|
||||
//go:embed analytics.go.tmpl
|
||||
var content embed.FS
|
||||
|
||||
// List of compiled go-templates
|
||||
|
||||
Reference in New Issue
Block a user