mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-03-20 19:50:47 -05:00
* fix: add type override in sqlc.yaml * chore: gen sqlc * chore: big find and replace * chore: more * fix: clean up bunch of outdated `.Valid` refs * refactor: remove `sqlchelpers.uuidFromStr()` in favor of `uuid.MustParse()` * refactor: remove uuidToStr * fix: lint * fix: use pointers for null uuids * chore: clean up more null pointers * chore: clean up a bunch more * fix: couple more * fix: some types on the api * fix: incorrectly non-null param * fix: more nullable params * fix: more refs * refactor: start replacing tenant id strings with uuids * refactor: more tenant id uuid casting * refactor: fix a bunch more * refactor: more * refactor: more * refactor: is that all of them?! * fix: panic * fix: rm scans * fix: unwind some broken things * chore: tests * fix: rebase issues * fix: more tests * fix: nil checks * Refactor: Make all UUIDs into `uuid.UUID` (#2897) * refactor: remove a bunch more string uuids * refactor: pointers and lists * refactor: fix all the refs * refactor: fix a few more * fix: config loader * fix: revert some changes * fix: tests * fix: test * chore: proto * fix: durable listener * fix: some more string types * fix: python health worker sleep * fix: remove a bunch of `MustParse`s from the various gRPC servers * fix: rm more uuid.MustParse calls * fix: rm mustparse from api * fix: test * fix: merge issues * fix: handle a bunch more uses of `MustParse` everywhere * fix: nil id for worker label * fix: more casting in the oss * fix: more id parsing * fix: stringify jwt opt * fix: couple more bugs in untyped calls * fix: more types * fix: broken test * refactor: implement `GetKeyUuid` * chore: regen sqlc * chore: replace pgtype.UUID again * fix: bunch more type errors * fix: panic
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
package posthog
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/posthog/posthog-go"
|
|
)
|
|
|
|
type PosthogAnalytics struct {
|
|
client *posthog.Client
|
|
}
|
|
|
|
type PosthogAnalyticsOpts struct {
|
|
ApiKey string
|
|
Endpoint string
|
|
}
|
|
|
|
func NewPosthogAnalytics(opts *PosthogAnalyticsOpts) (*PosthogAnalytics, error) {
|
|
if opts.ApiKey == "" || opts.Endpoint == "" {
|
|
return nil, fmt.Errorf("api key and endpoint are required if posthog is enabled")
|
|
}
|
|
|
|
phClient, err := posthog.NewWithConfig(
|
|
opts.ApiKey,
|
|
posthog.Config{
|
|
Endpoint: opts.Endpoint,
|
|
},
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create posthog client: %w", err)
|
|
}
|
|
|
|
return &PosthogAnalytics{
|
|
client: &phClient,
|
|
}, nil
|
|
}
|
|
|
|
func (p *PosthogAnalytics) Enqueue(event string, userId string, tenantId *uuid.UUID, set map[string]interface{}, metadata map[string]interface{}) {
|
|
|
|
var group posthog.Groups
|
|
|
|
if tenantId != nil {
|
|
group = posthog.NewGroups().Set("tenant", *tenantId)
|
|
}
|
|
|
|
var _ = (*p.client).Enqueue(posthog.Capture{
|
|
DistinctId: userId,
|
|
Event: event,
|
|
Properties: map[string]interface{}{
|
|
"$set": set,
|
|
"$metadata": metadata,
|
|
},
|
|
Groups: group,
|
|
})
|
|
}
|
|
|
|
func (p *PosthogAnalytics) Tenant(tenantId uuid.UUID, data map[string]interface{}) {
|
|
var _ = (*p.client).Enqueue(posthog.GroupIdentify{
|
|
Type: "tenant",
|
|
Key: tenantId.String(),
|
|
Properties: map[string]interface{}{
|
|
"$set": data,
|
|
},
|
|
})
|
|
}
|