Closed roelvanduijnhoven closed 2 years ago
We could change https://github.com/br33f/php-GA4-Measurement-Protocol/blob/master/src/Dto/Event/AbstractEvent.php#L172 to the following to resolve this probably:
'params' => new \ArrayObject($preparedParams)
But: it also depends on the given http library. Maybe it would be better to send JSON to the http client instead. So that we are not dependent on the underlying HTTP adapter.
Would you be open to accept this PR @br33f? If so: I'll prepare one.
@roelvanduijnhoven Sure - please go ahead with the PR
@br33f Glad this is fixed; Could you push a new release to packagist?
Cheers
Given the following piece of code:
With the comment this will lead into this error message from the Analytics API:
And that is because params will be sent as an empty array, instead of an empty object.
You can see that by looking at
$request->getExport()
for the situation with the comment:Versus without:
And that really is due to how json_encode works. We can probably solve this cleanly by working with an
ArrayObject
internally instead of a plain array. Why? Look at this: