Skip to content

Commit

Permalink
Docs: add umami analytics (#1626)
Browse files Browse the repository at this point in the history
Signed-off-by: Carson Yang <[email protected]>
  • Loading branch information
yangchuansheng authored May 29, 2024
1 parent 1e48922 commit 1db8161
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docSite/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ defaultContentLanguage = 'zh-cn'
# ["Something else"]
# ]

[params.umamiAnalytics]
websiteid = "69b3f2c6-39a5-4937-b92d-6fdd5c8f5958"
domain = "umami.fastgpt.in"
scriptName = "fastgpt"

[menu]
[[menu.primary]]
name = "Docs"
Expand Down
16 changes: 16 additions & 0 deletions docSite/layouts/partials/docs/analytics/umami.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{ if isset site.Params.umamiAnalytics "domain" }}
<script data-id="umami-script" async src="https://{{ site.Params.umamiAnalytics.domain }}/{{ site.Params.umamiAnalytics.scriptName }}" data-website-id="{{ site.Params.umamiAnalytics.websiteid }}">
</script>
{{ else }}
<script data-id="umami-script" async src="https://analytics.umami.is/script.js" data-website-id="{{ site.Params.umamiAnalytics.websiteid }}">
</script>
{{ end }}

<script type="text/javascript">
document.querySelector('script[data-id="umami-script"]').addEventListener('load', function () {
const type = document.head.querySelector('meta[property = "og:type"]').getAttribute('content');
let title = document.head.querySelector('meta[property = "og:title"]').getAttribute('content');
let url = document.head.querySelector('meta[property = "og:url"]').getAttribute('content');
umami.track(type + ':' + title, {'url': url});
});
</script>
5 changes: 5 additions & 0 deletions docSite/layouts/partials/docs/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
{{- end -}}
{{- end -}}
<!-- change -->
{{- if not .Site.IsServer }}
{{ with site.Params.umamiAnalytics.websiteid }}
{{- partialCached (printf "%s/%s" ($.Scratch.Get "pathName") "analytics/umami.html") . -}}
{{ end }}
{{ end }}
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/style.css" as="style" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/style.css" />
</head>

0 comments on commit 1db8161

Please sign in to comment.