Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate search analytics event captures #535

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/src/components/LegacyBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function LegacyBanner() {
<AlertCircle className="h-4 w-4 text-brand-400/80" />
<span>
You are reading a{' '}
<span className="text-brand-400/90">legacy (pre v.1.0)</span>{' '}
<span className="text-brand-400/90">legacy (pre v1.0)</span>{' '}
document.
</span>
</div>
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ function useAutocomplete({ close }: { close: () => void }) {
>({})

const captureSearchEvent = useDebounceCallback(
(query: string, results_count: number) =>
(query: string, results_count: number) => {
// return when length <= one, because this occurs when query is
// erased & last event on debounce stack is let through with 1 char
if (query.length <= 1) return

posthog.capture('searched docs', {
query,
results_count,
}),
})
},
500
)

Expand Down Expand Up @@ -95,7 +100,7 @@ function useAutocomplete({ close }: { close: () => void }) {
onStateChange({ state }) {
setAutocompleteState(state)

if (state.query) {
if (state.query && state.status === 'loading') {
captureSearchEvent(
state.query,
state.collections[0]?.items.length || 0
Expand Down
Loading