Say you have multiple trusted hosts configured in Matomo:
They are all used for different purposes/sites. When we currently get
SettingsPiwik::getMatomoUrl() the last used URL will be used. This will be used for example in scheduled reports. When then sending out the email, one of those URLs will be used randomly depending on which one was used last.
However, a user might want to force the usage of a specific trusted host when accessing a site and maybe wants to force the usage of a specific host in emails etc.
The same applies to Tag Manager containers which contains a preview URL when the preview mode is enabled. Depending on which URL was used last, the preview URL will use that trusted host. However, you may want to enforce loading the preview file from a specific trusted host for a specific site.
Like you want to configure:
idSite = 1 use foo.example.com idSite = 3 use bar.example.com idSite = 8 use analytics.example.com
something like this could be done for example in the
config.ini.php or in
config.php or it could be even simpler that we configure it in the
options DB .
Basically we would need a new parameter like
SettingsPiwik::getMatomoUrl($idsite = false) and when a specific idSite is given, then we first look if there's a matomo URL for the specific site and if not, behave as usual where we return the last used URL.
Internally this could look like: check
option_name=piwikUrl_$idSite. If it exists, use that URL.... if it doesn't exist, check
piwikUrl. A user could configure it by setting the correct entry in the option table. As this would be rarely used, a setting in the config might be too much.
Note: if the stored URL in
piwikUrl_$idSite (eg piwikUrl_3) is not a trusted host, we would also fallback to
I reckon with tests this can be done in like 4-8 hours as not too much logic needs to be changed. We would also change a few usages of
SettingsPiwik::getMatomoUrl() to pass the
idSite as an argument when the idSite is available.
BTW, this might also help for people who use Matomo Tag Manager with multiple different hostnames.
Currently whenever we load the MTM Preview Mode, it will use the piwikUrl from the database to fetch some of the resources (Logo, css files, etc)