Skip to content

Add Matomo analytics support #451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ disableHugoGeneratorInject = false
# theme = ""
#

# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Addon: Matomo Analytics
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# [params.matomo]
# enable = true # To enable matomo analytics change to `true`.
# websiteDomain = "my-cool-blog.website.tld" # Set the domain name of your website, in most cases same as your base URL this is required.
# domain = "bigbrother.website.tld" # Set to Matomo domain
# siteID = "1337" # Default is set to 1, change this to the siteid being tracked

# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Addon: Social icons
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Expand Down
5 changes: 5 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
{{ template "_internal/google_analytics.html" . }}
{{- end }}

<!-- Matomo Analytics -->
{{- if .Site.Params.matomo.enable }}
{{- partial "matomo.html" . }}
{{- end }}

<!-- Plausible.io -->
{{- if $.Site.Params.plausibleDataDomain }}
<script defer data-domain="{{ .Site.Params.plausibleDataDomain }}" src="{{ .Site.Params.plausibleScriptSource }}"></script>
Expand Down
23 changes: 23 additions & 0 deletions layouts/partials/matomo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- $config := site.Params }}
{{- $matomo := $config.matomo }}
{{- if ($matomo.enable) }}
<!-- Matomo -->
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.{{ $matomo.websiteDomain }}"]);
_paq.push(["setDomains", ["*.{{ $matomo.websiteDomain }}"]]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://{{ $matomo.domain }}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{{ default 1 $matomo.siteID }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="https://{{ $matomo.domain }}/matomo.php?idsite={{ default 1 $matomo.siteID }}&amp;rec=1" style="border:0;" alt="" /></p></noscript>
<!-- End Matomo Code -->
{{- end }}