I didn’t have any luck with the plugin.
I’ll share what I’m doing. Keep in mind that I’m not using an inherited theme. Instead, I’m modifying a theme (Quark, in my case) directly. If your theme is an inherited theme, you may want to adjust accordingly.
user/blueprints/config/site.yaml
:
@extends:
'@parent'
form:
fields:
content:
fields:
matomo_tracking_code:
type: editor
size: large
label: 'Matomo Tracking Code'
help: 'The tracking code given by Matomo setup goes here'
codemirror:
mode: 'javascript'
indentUnit: 2
autofocus: true
indentWithTabs: false
lineNumbers: true
styleActiveLine: true
gutters: ['CodeMirror-lint-markers']
lint: true
After adding the above blueprint, you can go into the grav admin > Configuration > Site and add the tracking code that Matomo gives you under “Matomo Tracking Code”. This will place an item matomo_tracking_code
in users/config/site.yaml
.
(Or if you’re not using the admin panel, you can skip the blueprint above, and just add an item to users/config/site.yaml
like this:
matomo_tracking_code: "[your tracking code here]"
)
Create file themes/[your theme or inherited theme]/templates/partials/matomo.html.twig
:
{% if site.matomo_tracking_code %}
{% set matomo = site.matomo_tracking_code %}
{{ matomo|raw }}
{% endif %}
In user/themes/templates/partials/base.html.twig
add the following just above the </head>
tag:
{% include 'partials/matomo.html.twig' %}
(Note: if you’re using an inherited theme, you may not want to create a modification of base.html.twig
. In that case, you can place the above include
in default.html.twig
or modular.html.twig
, and so on, of your inherited theme.)
The strategy I used above is slightly more complicated than the minimum that would be necessary. The very minimum would simply be to ignore all of the files except base.html.twig
and add the HTML tracking code that Matomo gives you directly to it (in place of the include
that I described above).
Hope that helps. And in answer to your question 3, in my experience, Matomo collects information instantly. On your Matomo dashboard, if you click “Visits in Real-time”, you should see any visitors displayed right away.