@SVyatoslavG opened this Issue on November 9th 2017

Hi everyone.
I am getting this error very ofter.
Error in Piwik (tracker): Invalid idSite: '0', referer: http://www.example.com/my-page.html
I have site with about 100.000 pageviews per week and this error happens ones every 10-15 second in the apache log.
It definitely comes from core/Tracker/Request.php
core/Tracker/Request.php
Is there any solution for this? I believe its a bug because I have only 1 site with PIWIK tracking code installed and about half of traffic actually makes on the PIWIK end.

@sgiehl commented on November 13th 2017 Member

Maybe the tracking code is not integrated correctly at some point. Would you mind sharing the site you are tracking. I would have a short look if everything is correct...

@Sudrien commented on April 4th 2018

Since the original poster didn't provide, here's my examples from this evening, with slight redaction:

2018/04/03 23:41:55 [error] 22749<a href='/0'>#0</a>: *2338 FastCGI sent in stderr: "PHP message: Error in Matomo (tracker): Invalid idSite: '0'" while reading response header from upstream, client: 182.253.139.67, server: m.sudrien.net, request: "GET /js/?pg=*****&appid=5&lt=log&pv_rf=https%3A%2F%2Fwww.google.co.id%2F&uuid=e880d415-6fcd-4963-9953-ed43f074c0ea&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=1&java=1&gears=0&ag=0&cookie=1&res=1366x768&gt_ms=581 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "*****", referrer: "*****"
2018/04/04 00:10:02 [error] 22749<a href='/0'>#0</a>: *3966 FastCGI sent in stderr: "PHP message: Error in Matomo (tracker): Invalid idSite: '0'" while reading response header from upstream, client: 182.253.139.67, server: m.sudrien.net, request: "GET /js/?pg=*****&appid=5&lt=log&pv_rf=https%3A%2F%2Fwww.google.co.id%2F&uuid=e880d415-6fcd-4963-9953-ed43f074c0ea&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=1&java=1&gears=0&ag=0&cookie=1&res=1366x768&gt_ms=539 HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "*****", referrer: "*****"
  • It's Nginx
  • Site 0 has been deleted (consolidated with another)
  • using _paq.push(['setTrackerUrl', u+'js/']);
  • google.co.id does not show up in all of them, but frequently
@pablitok commented on June 18th 2018

Same problem here.

  • Nginx version: 1.12.0
  • Site 0 doesn't exists
  • The piwik js is inserted via google tag manager

    <!-- Piwik -->
    <script type="text/javascript">
      var _paq = _paq || [];
      _paq.push(["setDomains", [(...)]]);
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      _paq.push(['enableHeartBeatTimer', 10]);
      (function() {
        var u="https://(...).com/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', 1]);
    
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
      })();
    </script>
    <noscript><p><img src="https://(...).com/piwik.php?idsite=1" style="border:0;" alt="" /></p>
    </noscript>
@huang0808 commented on June 20th 2018

@SVyatoslavG I met this error too, Did you fix them? mysite is no idsite=0

@huang0808 commented on July 30th 2018

@pablitok @sgiehl how did you fix it? I met too.

@alekseyp commented on January 14th 2019

Same issue.

In my case it's trying to get appid instead of idsite and only for some users.
Is it possible it's doing it for mobile inapp views thinking it's an app and not mobile page?

@jimoquinn commented on March 20th 2019

In my case it was solved by changing idSite to idsite:

`


To:
`
@tsteur commented on March 20th 2019 Member

I'll close this issue as this should only happen when there is a typo in the tracking code or a wrong idSite is set in the tracking code due to some issue in the user's website / app. Feel free to comment if there's any issue in Matomo.

@Daijobou commented on September 22nd 2021

@tsteur
I don't think it's a typo in all cases. I have thousands of page views daily and only a handful of these messages. I rather suspect that someone has copied my page and is using it offline privately and that's why the error happens only a few handful daily. So it would be nice to be able to turn this warning off or otherwise suppress it in a meaningful way.

@tsteur commented on September 22nd 2021 Member

@Daijobou to suppress these errors, would it work to define for example a firewall rule or an .htaccess rule to block the request if the request goes to matomo.php or piwik.php and has a URL parameter idsite=0?

@tsteur commented on September 22nd 2021 Member

@Daijobou btw how did you embed the tracking code? If they copy / download the page then it should copy also the idsite unless you're using the tag manager and the idsite is defined through a variable.

@Daijobou commented on September 22nd 2021

If I have thousands of page views per day in matomo statistics and the "setSiteId" is set by the system in a single template file, so it can never be wrong, the problem is in my eyes somewhere else, if there are only ~ 1-15 error messages per day.

Maybe someone downloaded the page and changed the SiteId via Search&Replace or a browser plugin does something strange here.

Is it possible to make an extended log that shows the calling URL that generated the error? As long as the user does not enter the original domain name in the (windows) hosts file (localhost), it should be easier to find the source of the error. Also for people who actually have set the SiteId somewhere wrong.

@tsteur commented on September 22nd 2021 Member

@Daijobou if you are familiar with editing files on the server you could adjust this line in core/Tracker/Request.php and basically make that line say

throw new UnexpectedWebsiteFoundException('Invalid idSite: \'' . $idSite . '\'' . ($_SERVER['HTTP_REFERER'] ?? '') );
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php
index 2dd8be5579..1fcd92a0fe 100644
--- a/core/Tracker/Request.php
+++ b/core/Tracker/Request.php
@@ -606,7 +606,7 @@ class Request
         $idSite = $this->getIdSiteUnverified();

         if ($idSite <= 0) {
-            throw new UnexpectedWebsiteFoundException('Invalid idSite: \'' . $idSite . '\'');
+            throw new UnexpectedWebsiteFoundException('Invalid idSite: \'' . $idSite . '\'' . ($_SERVER['HTTP_REFERER'] ?? '') );
         }

         // check site actually exists, should throw UnexpectedWebsiteFoundException directly
@Daijobou commented on October 7th 2021

Oops, forgot to submit the text.

@tsteur Thanks. However, "HTTP_REFERER" does not tell on which page the error occurs, only where the user came from. ;)
I have test it and added the IP to the log output. To see if the error is generated by a single page visitor or multiple page visitors.

The error_log entries are strange, because there are entries from a IPs that have many 20-100 access_log entries but like 1-2 error_log entries for wrong idSite, but what is impossible. As I wrote, we have a single template and that contains a valid idSite value.

To me it currently seems more like extremely rarely the $_GET value for idSite is lost either by a server modul itself or by Matomo. Is there any way to view the real page where the error occurs?

@tsteur commented on October 7th 2021 Member

only where the user came from.

For the tracking request that would be the page where the tracking request is being issued. So exactly what we're after.

@Daijobou commented on October 13th 2021

I don't understand. HTTP_REFERER is the page you were on before. Its not the page that call idSite. Example:
I coming from another website (like google.com), so the HTTP_REFERER is empty.

But to answer; All URLs from HTTP_REFERER (if not empty) have a valid idSite.

@tsteur commented on October 13th 2021 Member

I don't understand. HTTP_REFERER is the page you were on before.

@Daijobou That's only for the main document. The tracking requests (and other similar requests) the HTTP Referrer is then the page that is issuing this request. AKA the page you are viewing currently. This means the above code should tell you all the pages that have idsite=0 embedded. I see you mention that on these pages they are non-empty.

Is your Matomo maybe hosted on a different domain? In that case you might not get the full URL as referrer because of a Referrer Policy: strict-origin-when-cross-origin header.

You could also try this:

 throw new UnexpectedWebsiteFoundException('Invalid idSite: \'' . $idSite . '\'' . ($_REQUEST['url'] ?? '') );
@Daijobou commented on October 17th 2021

@tsteur $_REQUEST['url'] and $_REQUEST['idsite'] is always empty in logfile. So I changed to $_SERVER['REQUEST_URI'] to show the current URI. I get this lines in errorlog:

"PHP message: Error in Matomo (tracker): Invalid idSite: '0' URI=/matomo.php?undefined&pv_id=ZHe5B6
"PHP message: Error in Matomo (tracker): Invalid idSite: '0' URI=/matomo.php?pg=title&appid=2&lt=log&pv_rf=https%3A%2F%2Fwww.bing.com%2F&uuid=f9c408a0...&pdf=1&qt=0&realp=0&wma=0&dir=0&fla=1&java=0&gears=0&ag=0&cookie=1&res=1366x768&gt_ms=333

This look like more a bug in matomo?

and since few days I get this new error message in errorlog:
"PHP message: Error in Matomo (tracker): Tracker API 'region' was used, requires valid token_auth"

What is that supposed to tell me? ;) I don't use a API and nothing changed in matomo.

@tsteur commented on October 18th 2021 Member

@Daijobou are you using the Matomo JavaScript tracker? Sounds like this is maybe used in a mobile app or so?

This Issue was closed on March 20th 2019
Powered by GitHub Issue Mirror