Skip to content

Conversation

@jaroslavstefanec
Copy link
Contributor

@jaroslavstefanec jaroslavstefanec commented Mar 20, 2025

This PR fixes a TypeError that occurs after upgrading to propably version 5.5.2 (reference to PR #535).

When calling runRealtimeReport(), the method expects an argument of type Google\Analytics\Data\V1beta\RunRealtimeReportResponse, but an array is being passed instead. This results in the following error:

TypeError: Spatie\Analytics\AnalyticsClient::runRealtimeReport(): Return value must be of type Google\Analytics\Data\V1beta\RunRealtimeReportResponse, Google\Analytics\Data\V1beta\RunReportResponse returned, array given (reference: #515 (reply in thread))

This fix will ensure that the request argument passed to runRealtimeReport() is correctly instantiated instantiated and that the time range is adjusted, as using a date range is no longer possible in real-time reports.

use Spatie\Analytics\Facades\Analytics;
use Spatie\Analytics\Period;

// number of active users in the last 30 minutes which is visible in GA4 -> reports -> realtime overview
$period = Period::create(Carbon::now()->subMinutes(29), Carbon::now());
Analytics::getRealtime(period: $period, metrics: ['activeUsers']);

@freekmurze freekmurze merged commit bc79534 into spatie:main Mar 21, 2025
19 checks passed
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants