Add matomo as an analytics provider (#553)

This commit is contained in:
foliet 2022-08-22 12:28:54 +08:00 committed by GitHub
parent 6e19c4eb15
commit 017a974ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 0 deletions

View File

@ -693,6 +693,13 @@ cloudflare_analytics:
# See: https://clarity.microsoft.com/
clarity_analytics: # <project_id>
# Matomo Analytics
# See: https://matomo.org/
matomo:
enable: false
server_url: # https://www.example.com/
site_id: # <your site id>
# Show number of visitors of each article.
# You can visit https://www.leancloud.cn to get AppID and AppKey.
leancloud_visitors:

View File

@ -3,3 +3,4 @@
{%- include 'growingio.njk' -%}
{%- include 'cloudflare.njk' -%}
{%- include 'microsoft-clarity.njk' -%}
{%- include 'matomo.njk' -%}

View File

@ -0,0 +1,4 @@
{%- if theme.matomo.enable %}
{{ next_data('matomo', theme.matomo) }}
{{ next_js('third-party/analytics/matomo.js') }}
{%- endif %}

View File

@ -0,0 +1,19 @@
/* global CONFIG */
if (CONFIG.matomo.enable) {
window._paq = window._paq || [];
const _paq = window._paq;
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
const u = CONFIG.matomo.server_url;
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setSiteId', CONFIG.matomo.site_id]);
const d = document;
const g = d.createElement('script');
const s = d.getElementsByTagName('script')[0];
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g, s);
}