diff --git a/appview/state/search.go b/appview/state/search.go index 90fc8c23..9c65c841 100644 --- a/appview/state/search.go +++ b/appview/state/search.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "github.com/posthog/posthog-go" "tangled.org/core/appview/db" "tangled.org/core/appview/models" "tangled.org/core/appview/pages" @@ -122,6 +123,26 @@ func (s *State) Search(w http.ResponseWriter, r *http.Request) { "sortParam", sortParam, ) + if !s.config.Core.Dev && query.String() != "" { + distinctId := s.oauth.GetDid(r) + if distinctId == "" { + distinctId = "anonymous" + } + go func() { + if err := s.posthog.Enqueue(posthog.Capture{ + DistinctId: distinctId, + Event: "search", + Properties: posthog.Properties{ + "query": query.String(), + "result_count": resultCount, + "method": method, + }, + }); err != nil { + l.Error("failed to enqueue posthog event", "err", err) + } + }() + } + err = s.pages.SearchRepos(w, pages.SearchReposParams{ LoggedInUser: s.oauth.GetMultiAccountUser(r), Repos: repos,