PostHog / posthog-java

Official PostHog java library
MIT License
8 stars 12 forks source link

Support Groups #26

Closed ericmeadows closed 1 year ago

ericmeadows commented 2 years ago

We are trying to use the product, and groups are not yet supported. Please create parity with the other languages in terms of features.

tiina303 commented 2 years ago

Workaround: you can use groups through providing $groups { 'company': 'id5'} like so in properties

ericmeadows commented 2 years ago

So something akin to the following, or does it need to be a string?

HashMap<String, String> groups = new HashMap<String, String>() {
    {
        put("groupId", groupId);
    }
};
HashMap<String, Object> eventData = new HashMap<String, Object>() {
    {
        put("dataKey1", dataValue1);
        put("dataKey2", dataValue2);
        put("$groups", groups);
    }
};
ericmeadows commented 2 years ago

Another quick item in the documentation is that id:5 does not let me know ahead of time if it will be 5, or id:5 in the stored data type.

tiina303 commented 2 years ago

Yes that looks right. Let me know if it didn't work. With "company" and "id:5" I was referring to the examples we use in the docs in other libraries (e.g. https://posthog.com/docs/integrate/server/python#group-analytics) - which is just a random name we picked to use, you could use names like "google", "meta" etc instead or whatever makes sense for your groups

ericmeadows commented 2 years ago

Thank you!! That worked. It might be good to add that in the documentation for Java because I thought groups was completely not supported.

skydowx commented 1 year ago

Is there a workaround to send group properties in Java?

ivanagas commented 1 year ago

This is now documented so closing 😄