matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.69k stars 2.62k forks source link

'today' and 'yesterday' return different results than using todays date and yesterdays date #10099

Open gleasj opened 8 years ago

gleasj commented 8 years ago

When pulling a report using the API (and python), the results that come back are inconsistent.

There seems to be something wrong with the date conversion.

Here is the query I am using, and the results that come back:

url = 'http://atlasco.piwik.pro/?module=API'
url += '&method=Live.getLastVisitsDetails'
url += '&doNotFetchActions=true'
url += '&idSite=3'
url += '&period=day'
url += '&date=' + date
url += '&segment=visitConvertedGoalId==12;customVariableName3==Regular%20User'
url += '&filter_limit=-1'
url += '&showColumns=userId,serverDatePretty,serverTimePretty'
url += '&format=json'
url += '&token_auth=###############' # token from piwik
C:\Users\Jon> piwik_report.py today
New registrations for today : 3
### userA ###@gmail.com Wednesday, April 27, 2016 18:48:26
### userB ### Wednesday, April 27, 2016 14:00:25
### userC ### Wednesday, April 27, 2016 11:28:46

C:\Users\Jon> piwik_report.py 2016-04-27
New registrations for 2016-04-27 : 4
### userA ### Wednesday, April 27, 2016 18:48:26
### userB ### Wednesday, April 27, 2016 14:00:25
### userC ### Wednesday, April 27, 2016 11:28:46
### userD ### Tuesday, April 26, 2016 11:44:10

C:\Users\Jon> piwik_report.py yesterday
New registrations for yesterday : 4
### userA ### Wednesday, April 27, 2016 18:48:26
### userB ### Wednesday, April 27, 2016 14:00:25
### userC ### Wednesday, April 27, 2016 11:28:46
### userD ### Tuesday, April 26, 2016 11:44:10

C:\Users\Jon> piwik_report.py 2016-04-26
New registrations for 2016-04-26 : 1
### userD ### Tuesday, April 26, 2016 11:44:10
tsteur commented 8 years ago

Did you execute this script on "April 27th"? What's your timezone for that site?

Btw: The displayed dates should be UTC

I think this might be related to https://github.com/piwik/piwik/issues/8761 and it may be related to https://github.com/piwik/piwik/blob/2.16.1/plugins/Live/Model.php#L485-L490

Can you maybe comment the line in https://github.com/piwik/piwik/blob/2.16.1/plugins/Live/Model.php#L489 and see if it works afterwards?

gleasj commented 8 years ago

This was executed on April 27, at approximately 11:00pm - Pacific Time.

If the displayed dates are UTC, then the input should also be UTC - otherwise it is really confusing trying to pull info out. A better option would be to be able to set local time and do everything that way - cause that is how humans think)

I am not running piwik on our own server, so I cannot comment those lines out - thnaks.

tsteur commented 8 years ago

The input basically means today in the website's timezone. The property you are likely printing here is serverTimePretty which basically means UTC but doesn't say it which is not ideal indeed.

gleasj commented 8 years ago

I think this should be re-opened as a bug. Regardless of whether it is printing UTC time or not, 'today' is reporting some of the same things as 'yesterday'. and 04/27 is reporting some of the same things as 04/26.

The report for those time periods should be mutually exclusive. Something cannot be both yesterday and today, or 4/26 and 4/27.

tsteur commented 8 years ago

The report for those time periods should be mutually exclusive. Something cannot be both yesterday and today, or 4/26 and 4/27.

that's very true. Sorry for closing it, I didn't really realize that point.

Re the API and the column name we likely cannot really change it as it would break many APIs etc.

mattab commented 8 years ago

Thanks for the report @gleasj

Note: this error should be restricted to the API method=Live.getLastVisitsDetails and maybe other Live.* APIs but as for the other plugins APIs it should work as expected.