Skip to content

Commit d3cddef

Browse files
feat(dashboard): track dashboard search
1 parent ad9e5c9 commit d3cddef

File tree

1 file changed

+27
-5
lines changed
  • packages/app/src/app/pages/Dashboard/Header

1 file changed

+27
-5
lines changed

packages/app/src/app/pages/Dashboard/Header/index.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useRef } from 'react';
22
import { useDebouncedCallback } from 'use-debounce';
33
import { Link, useHistory } from 'react-router-dom';
44
import { Combobox, ComboboxInput } from '@reach/combobox';
@@ -163,17 +163,38 @@ const SearchInputGroup = () => {
163163
new URLSearchParams(window.location.search).get('query') || ''
164164
);
165165

166+
const lastTrackedQuery = useRef<string | null>(null);
167+
166168
const search = (queryString: string) => {
169+
// Track search start when executing a new search query
170+
if (lastTrackedQuery.current !== queryString && queryString.length >= 1) {
171+
track('Dashboard - Topbar - Search');
172+
lastTrackedQuery.current = queryString;
173+
}
174+
167175
history.push(dashboardUrls.search(queryString, activeTeam));
168176
};
169177
const [debouncedSearch] = useDebouncedCallback(search, 200);
170178

179+
const onFocus = () => {
180+
track('Dashboard - Topbar - Search Focus');
181+
};
182+
171183
const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
172-
setQuery(event.target.value);
173-
if (event.target.value.length >= 1) {
174-
debouncedSearch(event.target.value);
184+
const newValue = event.target.value;
185+
186+
setQuery(newValue);
187+
188+
// Reset tracking when query becomes empty
189+
if (newValue.length === 0) {
190+
lastTrackedQuery.current = null;
191+
}
192+
193+
if (newValue.length >= 1) {
194+
debouncedSearch(newValue);
175195
}
176-
if (!event.target.value) {
196+
197+
if (!newValue) {
177198
history.push(dashboardUrls.recent(activeTeam));
178199
}
179200
};
@@ -214,6 +235,7 @@ const SearchInputGroup = () => {
214235
as={Input}
215236
value={query}
216237
onChange={onChange}
238+
onFocus={onFocus}
217239
// onKeyPress={handleEnter}
218240
placeholder="Search in workspace"
219241
icon="search"

0 commit comments

Comments
 (0)