How do I make Matomo for WordPress work when it is behind a CDN or proxy?
If you are using a service like CloudFront or CloudFlare, then you will need to follow these instructions to make sure everything works as expected:
Cookies
Make sure all cookies are forwarded eg to wp-content/plugins/matomo/app/*
as otherwise the standalone Matomo reporting UI, Matomo Tag Manager and the Matomo Admin UI won’t be able to recognise your WordPress login.
Tracking
To prevent for example devices from being not detected you should ideally exclude the CDN feature for the wp-content/plugins/matomo/app/matomo.php
tracking endpoint if any possible. This prevents that the tracking endpoint will be ever cached and that the original user agent will be forwarded instead of for example Amazon CloudFront
.
Trusted host warning
When viewing the Matomo reporting UI you may see a trusted host warning that says something like “You are now accessing Matomo from ABC, but Matomo has been configured to run at this address: XYZ. Matomo may be misconfigured”. You can workaround this by editing the Matomo config file. This FAQ describes how you can find the path to the Matomo config file.
Now that you know where the config file is located, edit the config file and add a new line below the already existing line that starts with trusted_hosts[] = "..."
. Enter the actual Matomo URL like this:
trusted_hosts[] = "https://the-url-that-was-already-defined..."
trusted_hosts[] = "https://my-actual-matomo.url"
Matomo URL (eg logo not showing or wrong link in an email)
You might also need to configure the proxy header URL as described in this FAQ in your config file (see how to locate the path to the config file). This is for example the case if the Matomo logo is failing to load. It might also fix an issue where a sent email from Matomo points to your internal proxy URL instead of the actual Matomo URL.
For example, if you are using CloudFlare, you may need to add this to your config file under the [General]
section:
proxy_client_headers[] = HTTP_CF_CONNECTING_IP
IP detection
If the location (continent, country, …) of your visitors is not detected correctly, then you likely need to go “WordPress Admin -> Matomo Analytics -> Settings -> Advanced” and configure an alternative Proxy IP Header
. Click here to get detailed instructions.