matomo-for-wordpress
matomo-for-wordpress copied to clipboard
WP. Fatal error: An unexpected website was found in the request. (UnexpectedWebsiteFoundException)
Cannot get the Matomo plugin to work on my WP site.
Right after I turn on the tracking, In the "Summary" I get:
Fatal error: Uncaught Piwik\Exception\UnexpectedWebsiteFoundException: An unexpected website was found in the request: website id was set to '716' . in /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php:155
Stack trace:
#0 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/plugins/SitesManager/API.php(244): Piwik\Site::setSiteFromArray('258', NULL)
#1 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php(480): Piwik\Plugins\SitesManager\API->getSiteFromId('258')
#2 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php(597): Piwik\Site::getFor('258', 'sitesearch')
#3 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/plugins/Actions/Actions.php(137): Piwik\Site::isSiteSearchEnabledFor('258')
#4 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/plugins/Actions/Reports/SiteSearchBase.php(36): Piwik\Plugins\Actions\Actions->isSiteSearch
And on the "Reporting" page it says
An unexpected website was found in the request: website id was set to '716'
Here is my System Report:
# Matomo
* Matomo Plugin Version: 4.2.0
* Config exists and is writable.: Yes ("$ABSPATH/wp-content/uploads/matomo/config/config.ini.php" )
* JS Tracker exists and is writable.: Yes ("$ABSPATH/wp-content/uploads/matomo/matomo.js" )
* Plugin directories: Yes ([{"pluginsPathAbsolute":"$ABSPATH\/wp-content\/plugins\/matomo\/plugins","webrootDirRelativeToMatomo":"..\/"}])
* Tmp directory writable: Yes ($ABSPATH/wp-content/cache/matomo)
* Matomo Version: 4.2.1
* Matomo Blog idSite: 716
* Matomo Install Version: 4.2.0 (Install date: 2021-03-25 19:25:33)
* Upgrades outstanding: No
* Upgrade in progress: No
## Endpoints
* Matomo JavaScript Tracker URL: ($site_url/wp-content/uploads/matomo/matomo.js)
* Matomo JavaScript Tracker - WP Rest API: ($site_url/wp-json/matomo/v1/hit/)
* Matomo HTTP Tracking API: ($site_url/wp-content/plugins/matomo/app/matomo.php)
* Matomo HTTP Tracking API - WP Rest API: ($site_url/wp-json/matomo/v1/hit/)
## Crons
* Server time: 2021-03-25 17:28:35
* Blog time: 2021-03-25 19:28:35 (Below dates are shown in blog timezone)
* Sync users & sites: Next run: 2021-03-26 19:25:33 (23 hours 56 min) ( Last started: 2021-03-25 19:25:34 (-3 min 1s). Last ended: 2021-03-25 19:25:34 (-3 min 1s). Interval: daily)
* Archive: Next run: 2021-03-25 20:25:33 (56 min 58s) ( Last started: 2021-03-25 19:25:34 (-3 min 1s). Last ended: 2021-03-25 19:25:35 (-3 min 0s). Interval: hourly)
* Update GeoIP DB: Next run: 2021-04-24 19:25:33 (29 days 23 hours) ( Last started: 2021-03-25 19:25:35 (-3 min 0s). Last ended: 2021-03-25 19:25:37 (-2 min 58s). Interval: matomo_monthly)
## Mandatory checks
* PHP version >= : ok
* PDO extension: ok
* PDO\MYSQL extension: ok
* MYSQLI extension: ok
* Other required extensions: ok
* Required functions: ok
* Required PHP configuration (php.ini): ok
* Directories with write access: ok
* Directories with write access for Tag Manager: ok
## Optional checks
* Tracker status: ok
* Memory limit: ok
* Time zone: ok
* Open URL: ok
* PageSpeed disabled: ok
* GD > 2.x + Freetype (graphics): ok
* Other extensions: ok
* Other functions: ok
* Filesystem: ok
* Last Successful Archiving Completion: ok
* Database abilities: ok
* Max Packet Size: ok
* Geolocation: ok
* Update over HTTPS: ok
* Writable JavaScript Tracker ("/matomo.js"): ok
* Supports Async Archiving: No
* Location provider ID: geoip2php
* Location provider available: Yes
* Location provider working: Yes
## Matomo Settings
* Track mode: default
* Track codeposition: footer
* Track api endpoint: default
* Track js endpoint: default
* Version history: 4.2.0
* Core version: 4.2.1
* Last tracking settings update: 1616693161
* Last settings update: 1616693161
## Logs
* None:
# WordPress
* Home URL: $site_url
* Site URL: $site_url
* WordPress Version: 5.7
* Number of blogs: 1
* Multisite Enabled: No
* Network Enabled: No
* WP_DEBUG: No
* WP_DEBUG_DISPLAY: Yes
* WP_DEBUG_LOG: No
* DISABLE_WP_CRON: -
* FORCE_SSL_ADMIN: Yes
* WP_CACHE: No
* CONCATENATE_SCRIPTS: -
* COMPRESS_SCRIPTS: -
* COMPRESS_CSS: -
* ENFORCE_GZIP: -
* WP_LOCAL_DEV: -
* DIEONDBERROR: -
* WPLANG: -
* ALTERNATE_WP_CRON: -
* WP_CRON_LOCK_TIMEOUT: 60
* WP_DISABLE_FATAL_ERROR_HANDLER: -
* MATOMO_SUPPORT_ASYNC_ARCHIVING: -
* MATOMO_TRIGGER_BROWSER_ARCHIVING: -
* MATOMO_ENABLE_TAG_MANAGER: -
* MATOMO_SUPPRESS_DB_ERRORS: -
* MATOMO_ENABLE_AUTO_UPGRADE: -
* MATOMO_DEBUG: -
* MATOMO_SAFE_MODE: -
* MATOMO_GLOBAL_UPLOAD_DIR: -
* MATOMO_LOGIN_REDIRECT: -
* Permalink Structure: /%postname%/
* Possibly uses symlink: No
* Compatible content directory: Yes
# WordPress Plugins
## MU Plugins
* installatron_hide_status_test.php:
## Plugins
* Elementor: 3.1.4
* Elementor Pro: 3.2.0
* Matomo Analytics - Ethical Stats. Powerful Insights.: 4.2.0
* Polylang: 3.0.3
* Rank Math SEO: 1.0.60.1
* Active Plugins: 3 (elementor-pro elementor matomo)
* Theme: hello-elementor (hello-elementor)
# Server
* Server Info: Apache / ZoneOS
* PHP OS: Linux
* PHP Version: 7.4.13
* PHP SAPI: cgi-fcgi
* PHP Binary Name: php-cgi
* PHP Error Reporting: 0 After bootstrap: 0
* PHP Found Binary: php -q
* Timezone: UTC
* WP timezone: +02:00
* Locale: en_US
* User Locale: en_US
* Memory Limit: 1024M (At least 128MB recommended. Depending on your traffic 256MB or more may be needed.)
* WP Memory Limit: 40M
* WP Max Memory Limit: 1024M
* Timezone version: 2020.4
* Time: 1616693316
* Max Execution Time: 30
* Max Post Size: 2047M
* Max Upload Size: 2146435072
* Max Input Vars: 20000
* Disabled PHP functions: No
* zlib.output_compression is off: Yes
* Curl Version: 7.73.0, OpenSSL/1.1.1h
* Suhosin installed: No
# Database
* MySQL Version: 5.5.5
* Mysqli Connect: Yes
* Force MySQL over Mysqli: No
* DB Prefix: mlbs_
* DB CHARSET: utf8
* DB COLLATE:
* SHOW ERRORS: No
* SUPPRESS ERRORS: No
* Uses Socket: No
* Uses IPv6: No
* Matomo tables found: 36
* Matomo users found: 2
* Matomo sites found: 0
* Required permissions: OK
# Browser
* Browser: (Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36 OPR/74.0.3911.218)
* Language: en-us,en
Hi @skrasii thanks for creating this issue and apologies for the trouble. For some reason it seems there was no site created. Could you maybe deactivate AND uninstall the plugin and then install it again to see if it works afterwards?
Dear @tsteur, thank you for your response! I have reinstalled the plugin several times to no avail. Same result. Here is a video: https://youtu.be/8RIa7ZIEjjE
Thanks for the video @skrasii
I still struggle understanding how this could possibly happen unfortunately. Sorry about that. Is there any chance you could execute a MySQL query in your WordPress database in case you have access to it?
If so, could you execute this query and let me know what it returns?
select * from wp_options where option_name like "matomo-site-id-%"
Good idea, @tsteur!
Maybe the plugin (in some places) is trying to use the default wp_ prefix instead of wpdb->prefix. Turned out my hosting provider (for security reasons) generates a random prefix for each wp install.

@skrasii thanks for this. Can you maybe delete that entry like
DELETE FROM mlbs_options WHERE option_name like "matomo-site-id-%"
and then, if possible, wait for a while until the cron should ideally recreate this entry with a correct idSite.
This might not fix it though. In your original issue it was complaining about ID 716 and now ID 815. Yet at the same time in your system report I see that the table mlbs_matomo_site must have 0 entries as it says * Matomo sites found: 0. It makes me think like something is creating a site (hence the ID of the site increases every time) but then it deletes the actual site somehow again.
I'm actually wondering if the issue would be maybe fixed by going to WP Admin Dashboard -> Matomo Analytics -> Settings -> Advanced and there disable the setting for delete data on uninstall. Just curious if this changes anything over time. Could you maybe disable this setting before deleting the above entry?
@tsteur, yes the ID of the site increases every time I reinstall the plugin.
DELETE FROM mlbs_options WHERE option_name like "matomo-site-id-%"
done. (before that I disabled the "data deletion on uninstall" setting). waited for a few hours, looks like the cron didn't start, since no entry has been recreated.
After I removed the DB entry, the error on the "Summary" page changed:
On "Summary" page
Before db entry removal:

After db entry removal:

On the "Reporting" page the matomo still saying "An unexpected website was found in the request: website id was set to '907' ." Even though the matomo-site-id-1 db entry doesn't exist.
Sorry for all the forth and back @skrasii . The ID increased again by 100 from 815 to 907. I suppose you didn't uninstall it that often? That's why I'm thinking something might be uninstalling the plugin constantly or so.
@tsteur it is ok. I uninstalled it only once and the id changed from 815 to 907. But the cron didn't fire at all. I will be happy to provide more details if you need.
Could it be related to WP running on a subdomain?
It shouldn't be related to a subdomain. Any chance you are familiar with patching files in your WordPress?
Any chance you could replace the file wp-content/plugins/matomo/classes/WpMatomo/Site/Sync.php with the content of this: https://raw.githubusercontent.com/matomo-org/wp-matomo/28397b4c6cc5a0c0060045badffa147a54fdbfe4/classes/WpMatomo/Site/Sync.php . This represents the following change: https://github.com/matomo-org/wp-matomo/pull/440/files
then try to open this URL (you need to prepend your subdomain):
/wp-admin/admin.php?page=matomo-systemreport&tab=troubleshooting
and then click on the Sync site button (if the page loads).
@tsteur thank you for the detailed instructions. I have replaced the code in the Sync.php file.
On the troubleshooting page I got this error after hitting the "Sync site" button:
Fatal error:
Uncaught Piwik\Exception\UnexpectedWebsiteFoundException: An unexpected website was found in the request: website id was set to '947' . in /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php:155
Stack trace:
#0 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/plugins/SitesManager/API.php(244): Piwik\Site::setSiteFromArray(947, NULL)
#1 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php(505): Piwik\Plugins\SitesManager\API->getSiteFromId(947)
#2 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Settings/Storage/Backend/SitesTable.php(98): Piwik\Site::getSite(947)
#3 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Settings/Storage/Storage.php(115): Piwik\Settings\Storage\Backend\SitesTable->load()
#4 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Settings/Storage/Storage.php(83): Piwik\Settings\Storage\Stor in /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Site.php on line 155
There has been a critical error on this website. Please check your site admin email inbox for instructions.
I thought, maybe the files are cached. So I hard-refreshed the troubleshooting page and clicked once again on "Sync site" button and got this:
Fatal error: Uncaught InvalidArgumentException: Empty cache id given in /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/vendor/matomo/cache/src/Lazy.php:99 Stack trace:
#0 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/vendor/matomo/cache/src/Lazy.php(92): Matomo\Cache\Lazy->checkId(0)
#1 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/vendor/matomo/cache/src/Lazy.php(77): Matomo\Cache\Lazy->getCompletedCacheIdIfValid(0)
#2 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Tracker/Cache.php(243): Matomo\Cache\Lazy->delete(0)
#3 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/core/Tracker/Cache.php(231): Piwik\Tracker\Cache::deleteCacheWebsiteAttributes('0')
#4 /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/plugins/SitesManager/API.php(755): Piwik\Tracker\Cache::regenerateCacheWebsiteAttributes(Array)
#5 /data01/virt78103/domeenid/www.krasii.ee/ir in /data01/virt78103/domeenid/www.krasii.ee/irina/wp-content/plugins/matomo/app/vendor/matomo/cache/src/Lazy.php on line 99
There has been a critical error on this website. Please check your site admin email inbox for instructions.
Hello @skrasii
Do you still encounter this issue with the latest plugin version?
Kind regards
Mat
Hello @skrasii
Without any answer, I close this issue. Feel free to open a new one if you still need further support. Kind regards
Mat