We often see users tracking traffic into no longer existing siteIds or siteIds that never existed.
In https://github.com/matomo-org/matomo/issues/7550 we already have an issue to report back tracking errors. As this is quite a big project, I think it would be valuable to start with some more simple use case.
When a site is being tracked into a website that doesn't exist anymore (we could have the highest siteId as option and check if
$trackedSiteId < $highestSiteId). If so, we could report this in some way to the super user (as the site no longer exist it cannot be reported to any admin or view user).
FYI: I wouldn't show it for
$trackedSiteId > $highestSiteId as you could send lots of random requests to users every day annoying them by getting notifications about wrong requests and bloating tracker cache etc.
The question is where to store this info efficiently and where to show it.
Regarding storing: We could store it in a simple table or option table or something. To minimize DB requests during tracking we would have in cache
highestSiteId and all currently wrong tracked siteIds. This way we hit the DB only once per site.
We would maybe reset the list of "wrong tracked siteIds" daily or weekly. It would be also good to store along this info at what time we received the first wrong tracking request for that site and on which URL.
Regarding showing the notice: Not sure. Maybe weekly we could send a summary mail if there is one or multiple siteIds still in use? In the admin we could maybe have a screen for this under diagnostics and maybe a notification if data is tracked into a wrong siteId?
Regarding storing: We could store it in a simple table or option table or something. To minimize DB requests during tracking we would have in cache highestSiteId and all currently wrong tracked siteIds. This way we hit the DB only once per site.
Not sure what I wrote here :) I presume we could simply check during the tracking request if the site exists, and if not, check if we have already marked the idSite as "received tracking request but does not exist".