-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for error with empty "Unique users" for today/yesterday on Filament v.2 #67
Comments
Something like this should fix the problem with the visitors feature. Also, looks like, you should replace period with Carbon::today() otherwise we get data for yesterday. in Traits/Visitors.php
private function visitorsToday(): array
{
$analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::create(Carbon::today(), Carbon::today()));
return [
'result' => $analyticsData[0]['activeUsers'] ?? 0,
'previous' => $analyticsData[1]['activeUsers'] ?? 0,
];
} Same problem may happen with Page Views, if data for yesterday will be 0. private function visitorsYesterday(): array
{
$analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::create(Carbon::yesterday()->clone()->subDay(), Carbon::yesterday()));
return [
'result' => $analyticsData[0]['activeUsers'] ?? 0,
'previous' => $analyticsData[1]['activeUsers'] ?? 0,
];
} In src/Traits/PageViews.php private function pageViewsToday(): array
{
$analyticsData = Analytics::fetchTotalVisitorsAndPageViews(Period::create(Carbon::today(), Carbon::today()));
return [
'result' => $analyticsData->last()['screenPageViews'] ?? 0,
'previous' => $analyticsData->first()['screenPageViews'] ?? 0,
];
} It's possible that other widgets have the same problem, but I haven't tested that. |
Please double check everything, or I can help you with a fix if needed, but inconsistent data is the last thing users like... And I really appreciate your work. |
@bezhanSalleh could you please participate? |
for some reason i wasn't watching this repo. apologies for the very late reply. |
Hi, okay, keep me posted, I'm still waiting for any updates. |
ok, so i have read your comments but could you clarify a couple of things: first about the versioning you mentioned; |
@bezhanSalleh, hello, we have downgraded package, yes, it fixed 500 error, but this error still here. |
@bezhanSalleh also, looks like something wrong with "Avg. Sessions Duration". |
yeah, I have checked and the only inconsistency was for the |
@bezhanSalleh, yes, okay, I'll check it now, but what about session duration? In public function
that gives us a correct value but without leading zero |
@bezhanSalleh
|
@bezhanSalleh Also, the average session duration for today is incorrect, it's yesterday's data. |
man, i need to sleep... ben up closing to 48hrs now... was in the wrong branch when made the release 🤦🏻♂️ |
Okay, bro, no problems, check it out when you can. |
i know, but the api response for duration is in seconds so instead we use |
new releases with fix Filam.v2 => 1.1.4 & Filam.v3 => 2.0.3. cheers! |
Yes, @bezhanSalleh, I so appreciate your work and only two things that I see as a possible bug. This way to get today's and yesterday's dates used for both packages for Filament 2 and Filament 3, IDK why exactly this way is used in your function, but maybe I got something wrong? I offer to replace today's functions with this way (example)
And yesterday's functions (example)
|
yeah, so after i had some shut eye i reviewed it thoroughly. return match (true) {
($results->containsOneItem() && ($results->first()['date'])->isYesterday()) => [
'previous' => $results->first()['value'],
'result' => 0,
],
($results->containsOneItem() && ($results->first()['date'])->isToday()) => [
'previous' => 0,
'result' => $results->first()['value'],
],
$results->isEmpty() => [
'previous' => 0,
'result' => 0,
],
default => [
'previous' => $results->last()['value'] ?? 0,
'result' => $results->first()['value'] ?? 0,
]
}; now update your composer to make sure you are on the latest version based on your filament version and hopefully this will be it. so let me know. cheers! |
@RChutchev i will have a look over the weekend to make sure the others will have the same fix. cause i know the page views and unique visitors do require the same check. |
Yes, I'll test it now. Thank you so much! Also, I opened a pull request to add a Russian language translation, I hope it will be merged, maybe someone else requires it too |
Screen.Recording.2024-10-24.at.3.03.02.AM.mov@RChutchev as you can see in the above screenshots, you can see we don't have anything for 24, so now the |
Yes, right, I just updated the package to 1.2.0 for local env, and yes, it now shows me 0 for empty values for sessions and average. session duration, and when some data comes from GA I am sure data will also be shown. |
@bezhanSalleh, hi, I've tested the last released version, and it looks like the "sessions count" and the "average sessions duration" for today do not work well, and always show 0 as values whatever Google Analytics has value. |
That might be the issue with your cache setting, because the base spatie package caches the query result for 24hrs. |
Thanks a lot, yep, I forgot about the Spatie package cache. |
I've same problem (#38) with your package on ver. 2.0.0, with Filament v.2, with about to empty GA data, on test environment. We're unable to use package without pass all tests on Test environment (b/c some time it's possible to have 0 as "today unique users" for example at 0:01AM for current day.
We're unable to update to Filament v.3 for some reasons.
Can u please add same fix for your package (2.0.0 ver) b/c 2.0.0 ver last supported version for Filament v.2, or add support for Filament v.2 to 2.0.1 package version if 2.0.1 works with Filament v.2.
vendor/bezhansalleh/filament-google-analytics/src/Traits/Visitors.php
It's require to modify this function
and here too, to be sure that we are never get 500 if data empty...
Originally posted by @RChutchev in #38 (comment)
The text was updated successfully, but these errors were encountered: