PostHog / posthog-go

Official PostHog Go library
MIT License
20 stars 17 forks source link

Add support for group analytics #4

Closed liyiy closed 2 years ago

liyiy commented 2 years ago

Add support for group analytics

To add/identify a group:

// basic:

client.Enqueue(posthog.groupIdentify{
       Type: "organization",
       Key: "id:5",
   })

// advanced:

client.Enqueue(posthog.groupIdentify{
      Type: "organization",
      Key: "id:5",
      Properties: posthog.NewProperties().
        Set("trait", "value").
        Set("instance", "app.posthog.com"),
    })

To capture with a group:

client.Enqueue(posthog.Capture{
      DistinctId: "test-user",
      Event:      "$pageview",
      Groups:    posthog.NewGroups().
        Set("company", "id:5").
        Set("instance", "app.posthog.com") 
  })
liyiy commented 2 years ago

Also I don't understand why this is an invalid response if it's exactly the same? 👀

Screen Shot 2021-10-26 at 4 22 57 PM
macobo commented 2 years ago

properties.$group_set is different on the two responses.

for example message_id and context don't seem to exist in the identify calls here thinking so I wasn't sure

Those are posthog-python specific values it seems.

macobo commented 2 years ago

Please update the PR description to include how:

  1. Capturing an event with groups looks
  2. Setting group properties works

I'll be using these examples for documentation but it's good practice to include information like this in the PR description.

macobo commented 2 years ago

This change does not work, created a test script based on the PR description.

⟩ go run test-script.go                                                                                                                                                                                    09:55:31
# command-line-arguments
./test-script.go:21:17: cannot refer to unexported name posthog.groupIdentify
./test-script.go:26:17: cannot refer to unexported name posthog.groupIdentify

Taking over and seeing how I can get this functional. :)

Edit: The issue was with the PR description - the example was wrong. Code itself does work.