matomo-org / plugin-AnonymousPiwikUsageMeasurement

Help making Matomo better by sending anonymized usage data to the creators the project, and/or to your own Matomo instance and/or to any other Matomo instance
https://plugins.matomo.org/AnonymousPiwikUsageMeasurement
GNU General Public License v3.0
4 stars 12 forks source link

Make AnonymousPiwikUsageMeasurement::TRACKING_DOMAIN configurable instead of hardcoded #58

Open blankster opened 3 years ago

blankster commented 3 years ago

I was trying out this plugin but wasn't unable to get it running - till I found out that in the website configuration I try to track to, I must uncheck this

image

or must include "http://demo-anonymous.matomo.org" too, otherwise, the tracking didn't work.

Is this a relic from the past when usage data was optionally sent to matomo.org? Is it a bug? Or am I overlooking something obvious?

Thanks in advance for your help and work!

diosmosis commented 3 years ago

Hi @blankster, could you tell us what are you trying to use the plugin for?

blankster commented 3 years ago

Hi @diosmosis ,

Of course! I'm trying to use the plugin to track the usage of Matomo itself (which, as I understand it, is the intended use for it).

Let's assume that Matomo is accessible via the subdomain https://stats.domain.com. I've installed the plugin and created a new website for https://stats.domain.com. This website is configured to only accept tracking visits and actions from the URL https://stats.domain.com. Then I configured the plugin with the ID of this newly created website.

This doesn't work and only worked when I accepted also trackings from http://demo-anonymous.matomo.org OR unchecked the option to only accept trackings from the listed URLs.

In my opinion, the generated JS code the plugin inserted for tracking Matomo itself isn't correct as it looks like this then:

var piwikUsageTracking = {"targets":[{"url":"https:\/\/stats.domain.com\/matomo.php","idSite":3,"useAnonymization":true}],"visitorCustomVariables":[{"id":1,"name":"Access","value":"superuser"}],"trackingDomain":"https:\/\/demo-anonymous.matomo.org","exampleDomain":"http:\/\/example.com","userId":"my.user"};

The configuration of the plugin looks like this: image

Am I overlooking something obvious?

diosmosis commented 3 years ago

@blankster I looked at the code, and the URL is hardcoded here: https://github.com/innocraft/matomo-cloud/blob/develop/plugins/AnonymousPiwikUsageMeasurement/AnonymousPiwikUsageMeasurement.php#L47 . Thinking about it, I believe this is intended. The primary use case for us was to get some light usage measurement stats from other users' Matomo instances, rather than a single instance, and this URL is used to anonymize their hostname in the page URL and other URLs matomo tracks. It shouldn't be an issue to accept visits to that URL also, but if you need it changed you could change it in the PHP (though you'd need to change it again after every Matomo update).

blankster commented 3 years ago

@diosmosis thanks for your reply!

I think you meant https://github.com/matomo-org/plugin-AnonymousPiwikUsageMeasurement/blob/89715ebabd08baf78954fdac603a0ed3030d8f87/AnonymousPiwikUsageMeasurement.php#L20 right?

I read about the original purpose of the plugin, but even back then it was for matomo.org OR self-tracking. Now this original purpose is gone since a while and it tracks, in general, the wrong domain name as visible in the following:

image

It's certainly not the end of the world, but it's actually wrong and has no benefit, especially since tracking is done for a specific web page, which is referenced with the ID. Especially since the purpose of the plugin is now defined for tracking its own instance, the corresponding URL should also be used there, instead of a relic from the past as it is now.

My knowledge in Matomo context is too small to submit a PR with the right approach. Correct would be:

How could this be achieved?

PS: In my opinion, a lot more people should track the usage of their own instance, as it's surprising how many people try to access the instance (or even API) of a fresh installation on an URL, nobody knows (as the tracking - not the Matomo installation - is only used behind password protection and only the team has access to it).

diosmosis commented 3 years ago

in general, the wrong domain name as visible in the following:

This is the point, we don't want the original host's domains in the tracked data, since they would belong to other peoples' matomo instances. This is intended. You can change it manually in the code if you want, but we're probably not going to make it configurable any time in the near future as it wouldn't be a high priority for us.

blankster commented 3 years ago

This is the point, we don't want the original host's domains in the tracked data, since they would belong to other peoples' Matomo instances. This is intended.

For one specific use case: If people share their own Matomo usage to someone else, who should not know the real domain name Matomo is running on. This part I fully understand and also why it was built like this by intent.

But the current description isn't suggesting this use case:

Track usage of your Matomo service into up to two Matomos:

  • your own Matomo (can be configured optionally)
  • a custom Matomo (can be configured optionally)

At least the first use case a Matomo installation tracks to itself. That's the reason why just a website ID is needed. Here it makes in no situation sense to replace the domain with the demo domain. You know it because you've logged in on that domain :) In the 2nd use case, it could be also another self-hosted Matomo instance. As long as it's self-owned you want to know the correct domain. And based on the description of the plugin I think most people would expect that it's for tracking Matomo to a self-owned Matomo instance and not to share it with somebody else that requires to hide the domain.

You can change it manually in the code if you want, but we're probably not going to make it configurable any time in the near future as it wouldn't be a high priority for us.

Thanks - that helps to understand the situation.