PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
20.85k stars 1.24k forks source link

Make Group Analytics API RESTful #13537

Open Twixes opened 1 year ago

Twixes commented 1 year ago

Is your feature request related to a problem?

Currently the Group Analytics part of our API strongly relies on query parameters for resource access, and often uses verbs for that. Meanwhile persons, which are analogous to groups in our analytics model, have a much more resource-oriented API. Notably, resource-oriented APIs are easier to extend, as I'm experiencing right now implementing the properties timeline feature for groups – it was trivial to add it to persons' /api/projects/<project_id>/persons/<person_id>/ (just a properties_timeline GET action), but it's a mess to add it to groups' /api/projects/<project_id>/groups/find?group_type_index=<group_type_index>&group_key=<group_key>/ (a find action is completely non-conventional for particular-resource access).

Additionally, currently group_types and groups are on the same level, so when inevitably groups has to be filtered by a specific group type, the group_type_index query param is used. This would be much clearer if groups were nested under group_types. Think of /.../group_types/<group_type_index>/groups/ – no query params needed.

Describe the solution you'd like

List group types

No change: GET /projects/<project_id>/group_types/

List group property definitions for all group types

No change: GET /projects/<project_id>/groups/property_definitions/

Update group types metadata in batch

No change: PATCH /projects/<project_id>/group_types/update_metadata/ (this isn't very RESTful, but also not problematic now, and there's no REST convention for batch updates)

List groups of type

Before: GET /projects/<project_id>/groups?group_type_index=<group_type_index>/ After: GET /projects/<project_id>/group_types/<group_type_index>/groups/

Retrieve particular group

Before: GET /projects/<project_id>/groups/find?group_type_index=<group_type_index>&group_key=<group_key>/ After: GET /projects/<project_id>/group_types/<group_type_index>/groups/<group_key>/

List related persons and groups of particular group

Before: GET /projects/<project_id>/groups/related?id=<group_key>&group_type_index=<group_type_index>/ After: GET /projects/<project_id>/group_types/<group_type_index>/groups/<group_key>/related_actors/

List related groups of person

Before: GET /projects/<project_id>/groups/related?id=<person_uuid>/ (it isn't obvious at all from the path that this returns related groups of a person) After: GET /projects/<project_id>/persons/<person_uuid>/related_groups/

List values of property for group type

Before: GET /projects/<project_id>/groups/property_values?group_type_index=<group_type_index>&key=<property_key>/ After: GET /projects/<project_id>/group_types/<group_type_index>/property/<property_key>/values/

CC @macobo

kiran-4444 commented 11 months ago

Is anyone working on this yet? If not, I'd love to start on this.