Monorepo for Tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <anirudh@tangled.org>

authored by

Anirudh Oppiliappan and committed by
Tangled
7f149acc 33382a02

+21
+21
appview/state/search.go
··· 5 5 "strings" 6 6 "time" 7 7 8 + "github.com/posthog/posthog-go" 8 9 "tangled.org/core/appview/db" 9 10 "tangled.org/core/appview/models" 10 11 "tangled.org/core/appview/pages" ··· 121 122 "filterQuery", query.String(), 122 123 "sortParam", sortParam, 123 124 ) 125 + 126 + if !s.config.Core.Dev && query.String() != "" { 127 + distinctId := s.oauth.GetDid(r) 128 + if distinctId == "" { 129 + distinctId = "anonymous" 130 + } 131 + go func() { 132 + if err := s.posthog.Enqueue(posthog.Capture{ 133 + DistinctId: distinctId, 134 + Event: "search", 135 + Properties: posthog.Properties{ 136 + "query": query.String(), 137 + "result_count": resultCount, 138 + "method": method, 139 + }, 140 + }); err != nil { 141 + l.Error("failed to enqueue posthog event", "err", err) 142 + } 143 + }() 144 + } 124 145 125 146 err = s.pages.SearchRepos(w, pages.SearchReposParams{ 126 147 LoggedInUser: s.oauth.GetMultiAccountUser(r),