mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Add matomo as an analytics provider (#553)
This commit is contained in:
parent
6e19c4eb15
commit
017a974ef0
@ -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:
|
||||
|
||||
1
layout/_third-party/analytics/index.njk
vendored
1
layout/_third-party/analytics/index.njk
vendored
@ -3,3 +3,4 @@
|
||||
{%- include 'growingio.njk' -%}
|
||||
{%- include 'cloudflare.njk' -%}
|
||||
{%- include 'microsoft-clarity.njk' -%}
|
||||
{%- include 'matomo.njk' -%}
|
||||
|
||||
4
layout/_third-party/analytics/matomo.njk
vendored
Normal file
4
layout/_third-party/analytics/matomo.njk
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{%- if theme.matomo.enable %}
|
||||
{{ next_data('matomo', theme.matomo) }}
|
||||
{{ next_js('third-party/analytics/matomo.js') }}
|
||||
{%- endif %}
|
||||
19
source/js/third-party/analytics/matomo.js
vendored
Normal file
19
source/js/third-party/analytics/matomo.js
vendored
Normal 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);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user