Skip to content

Commit 889cc8e

Browse files
committed
fix
1 parent a446290 commit 889cc8e

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/Analytics.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,30 @@ public function getRealtimeReport(GoogleAnalyticsService $googleAnalytics): Anal
102102
}
103103

104104
/**
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.
105+
* Build the request parameters using the protobuf field names (snake_case)
106+
* and drop fields that were never set. The native protobuf extension is
107+
* strict about both: it rejects camelCase keys ("No such field dateRanges")
108+
* and null values ("Cannot convert '' to string"), while the pure-PHP
109+
* implementation silently tolerates them. Fields that do not apply to a
110+
* given request type stay empty and are filtered out here.
109111
*
110112
* @return array<string, mixed>
111113
*/
112114
protected function reportParameters(GoogleAnalyticsService $googleAnalytics): array
113115
{
114116
return array_filter([
115117
'property' => 'properties/'.$this->getPropertyId(),
116-
'dateRanges' => $googleAnalytics->dateRanges,
117-
'minuteRanges' => $googleAnalytics->minuteRanges,
118+
'date_ranges' => $googleAnalytics->dateRanges,
119+
'minute_ranges' => $googleAnalytics->minuteRanges,
118120
'dimensions' => $googleAnalytics->dimensions,
119121
'metrics' => $googleAnalytics->metrics,
120-
'orderBys' => $googleAnalytics->orderBys,
121-
'metricAggregations' => $googleAnalytics->metricAggregations,
122-
'dimensionFilter' => $googleAnalytics->dimensionFilter,
123-
'metricFilter' => $googleAnalytics->metricFilter,
122+
'order_bys' => $googleAnalytics->orderBys,
123+
'metric_aggregations' => $googleAnalytics->metricAggregations,
124+
'dimension_filter' => $googleAnalytics->dimensionFilter,
125+
'metric_filter' => $googleAnalytics->metricFilter,
124126
'limit' => $googleAnalytics->limit,
125127
'offset' => $googleAnalytics->offset,
126-
'keepEmptyRows' => $googleAnalytics->keepEmptyRows,
128+
'keep_empty_rows' => $googleAnalytics->keepEmptyRows,
127129
], fn (mixed $value): bool => $value !== null && $value !== []);
128130
}
129131
}

0 commit comments

Comments
 (0)