Skip to content
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

Wrong format for userProperties sent to GA4. #25

Open
bnoss opened this issue Mar 19, 2023 · 2 comments
Open

Wrong format for userProperties sent to GA4. #25

bnoss opened this issue Mar 19, 2023 · 2 comments

Comments

@bnoss
Copy link

bnoss commented Mar 19, 2023

UserProperties::export() returns data in wrong format, which ends with an error

"Unable to parse Measurement Protocol JSON payload. invalid JSON in google.analytics.measurement.Measurement @ user_properties: message google.analytics.measurement.Measurement.UserPropertiesEntry, near 1:333 (offset 332): unexpected character: '['; expected '{'"

The data has to be sent as an key->value paired array/object to analytics' endpoint (as described in its docs).

Suggest alternative to the original lines

    public function export(): array
    {
        return array_reduce($this->getUserPropertiesList(), function ($last, UserProperty $userProperty) {
            return array_merge($last, $userProperty->export());
        }, []);
    }

as in the following sample:

    public function export(): array
    {
        $return = [];
        foreach ($this->getUserPropertiesList() as $userProperty) {
            $return[array_keys($userProperty->export())[0]] = array_values($userProperty->export())[0];
        }
        return $return;
    }
@nicodemuz
Copy link

I'm encountering the same issue.

@nicodemuz
Copy link

The changes above by @bnoss fix the issue for me as well: 7d18a73

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

No branches or pull requests

2 participants