From 7f149acca55b516de13cd1fbcb81256a0d6e2876 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Tue, 21 Apr 2026 08:50:13 +0000 Subject: [PATCH] appview/state: add posthog capture for search Sets the distinct id to 'anonymous' for logged out searches. Let's stick to this for any future logged out events. Signed-off-by: Anirudh Oppiliappan --- appview/state/search.go | 21 +++++++++++++++++++++ 1 file(s) changed, 21 insertion(s)(+), 0 deletion(s)(-) diff --git a/appview/state/search.go b/appview/state/search.go --- a/appview/state/search.go +++ b/appview/state/search.go @@ -5,6 +5,7 @@ "strings" "time" + "github.com/posthog/posthog-go" "tangled.org/core/appview/db" "tangled.org/core/appview/models" "tangled.org/core/appview/pages" @@ -121,6 +122,26 @@ "filterQuery", query.String(), "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), -- tangled.sh