Closed OliverO2 closed 3 years ago
Hey Oliver, thanks for opening this Pull request.
Your ideas sound really good, I just got a few questions:
Currently I disable local/development tracking by using a dedicated config for localhost/development server. I simply disable the plugin or I use a different site config to track the hits on a different pool. I guess your solution is simpler, as it make no sense to track hits from localhost in most cases, was this the intention?
About the cookie: Currently you can honor the do not track setting of the browser. I understand that the cookie is just another option which is all good. But do we really need it? Just asking, cause you might not be aware of that setting.
I've got a question regarding this: https://github.com/escopecz/grav-ganalytics/pull/11/files#diff-37ce1af37fc02da4245eb958206ab395307b33f55b31256f202cc1631af6a972L86
I also stumbled across this. Can we use https also for matomo? Do you have any knowledge about that? Cause the usual tracking code of matomo use no https, I was wondering if it makes sense to add that here. I am always pro https!
I like the idea about adding an inline js blocking reason. Would you mind adding that as well? This looks like a good debugging idea to me. We could also use this here instead of throwing an exception. What do you think? https://github.com/NicoHood/grav-plugin-matomo/blob/develop/matomo.php#L109
Thanks for the quick reaction. Your questions are welcome, as to prevent bloat, a useful strategy is "no use case, so feature". ;-)
Considering the alternatives to a separate cookie:
Controlling tracking via the site configuration
localhost
configuration directs tracking to an internal Matomo test server. In this configuration I also change the default setting to:
blockedIpRanges: [] # allow connections within the local network
Using "Do not track"
So in my view the extra cookie is necessary as the alternatives require extra manual intervention and increase the error potential.
Regarding the use of https
: In the grav-ganalytics
plugin, I simply added a previously missing https:
scheme to the Google script link in that plugin's JS snippet. As far as I know, Matomo is already using https if possible (see getCurrentScheme()
in vendor/matomo/matomo-php-tracker/MatomoTracker.php
) so I'm not aware of any need to changes here.
I had thought about adding the blocking reason here as well. I initially decided against this to keep output clean, because with PHP-only tracking, no code will be injected into the page at all. In conjunction with a separate debug
configuration setting we can have both.
I have addressed your suggestions in my recent commit.
I've tagged a new release. Thanks for your patch, corrections and time :-)
Thanks for your reviews and your quick integration!
This pull request adds the following capabilities:
These features already exist in the Google Analytics plugin for Grav (introduced via my pull request there) and have been in production use for quite some time.
Rationale
Why block client IP address ranges?
If your Matomo plugin is configured to send tracking events to a production Matomo server on the Internet, it will also send tracking events there when you use it with a Grav testing server on your local network. This is usually undesirable.
The following (default) setting disables tracking when a client connects to the server via local networks, while leaving it on for production installations:
You may also specify your testing client address or your testing client's IPv4 or IPv6 address range in
blockedIpAddresses
orblockedIpRanges
respectively.Why use an additional blocking cookie?
Two reasons:
To allow users to opt out from PHP tracking. Unfortunately, Matomo's opt-out cookie works for JavaScript tracking only. It does not disable PHP tracking.
To test a production site without changing its configuration. The cookie can be used to exclude test clients from tracking, while leaving it enabled for everyone else.
How to set a blocking cookie?
Use this PHP script as is or adapt it to your needs: setGravMatomoTrackingPreferences.php