@@ -83,22 +83,7 @@ public function getReport(GoogleAnalyticsService $googleAnalytics): AnalyticsRes
8383 {
8484 $ client = $ this ->getClient ();
8585
86- $ parameters = [
87- 'property ' => 'properties/ ' .$ this ->getPropertyId (),
88- 'dateRanges ' => $ googleAnalytics ->dateRanges ,
89- 'minuteRanges ' => $ googleAnalytics ->minuteRanges ,
90- 'dimensions ' => $ googleAnalytics ->dimensions ,
91- 'metrics ' => $ googleAnalytics ->metrics ,
92- 'orderBys ' => $ googleAnalytics ->orderBys ,
93- 'metricAggregations ' => $ googleAnalytics ->metricAggregations ,
94- 'dimensionFilter ' => $ googleAnalytics ->dimensionFilter ,
95- 'metricFilter ' => $ googleAnalytics ->metricFilter ,
96- 'limit ' => $ googleAnalytics ->limit ,
97- 'offset ' => $ googleAnalytics ->offset ,
98- 'keepEmptyRows ' => $ googleAnalytics ->keepEmptyRows ,
99- ];
100-
101- $ response = $ client ->runReport (new RunReportRequest ($ parameters ));
86+ $ response = $ client ->runReport (new RunReportRequest ($ this ->reportParameters ($ googleAnalytics )));
10287
10388 return $ this ->formatResponse ($ response );
10489 }
@@ -111,7 +96,22 @@ public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): Anal
11196 {
11297 $ client = $ this ->getClient ();
11398
114- $ parameters = [
99+ $ response = $ client ->runRealtimeReport (new RunRealtimeReportRequest ($ this ->reportParameters ($ googleAnalytics )));
100+
101+ return $ this ->formatResponse ($ response );
102+ }
103+
104+ /**
105+ * Build the request parameters, dropping fields that were never set. The
106+ * native protobuf extension rejects null (and empty) values that the
107+ * pure-PHP implementation silently tolerates, so unset fields must be
108+ * omitted rather than passed through as null.
109+ *
110+ * @return array<string, mixed>
111+ */
112+ protected function reportParameters (GoogleAnalyticsService $ googleAnalytics ): array
113+ {
114+ return array_filter ([
115115 'property ' => 'properties/ ' .$ this ->getPropertyId (),
116116 'dateRanges ' => $ googleAnalytics ->dateRanges ,
117117 'minuteRanges ' => $ googleAnalytics ->minuteRanges ,
@@ -124,10 +124,6 @@ public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): Anal
124124 'limit ' => $ googleAnalytics ->limit ,
125125 'offset ' => $ googleAnalytics ->offset ,
126126 'keepEmptyRows ' => $ googleAnalytics ->keepEmptyRows ,
127- ];
128-
129- $ response = $ client ->runRealtimeReport (new RunRealtimeReportRequest ($ parameters ));
130-
131- return $ this ->formatResponse ($ response );
127+ ], fn (mixed $ value ): bool => $ value !== null && $ value !== []);
132128 }
133129}
0 commit comments