Skip to content

Commit 88a2aee

Browse files
authored
fix: ask-ai-click-test (#2909)
## Description Provide a concise summary of the changes made in this pull request - ## Pull request type Check the appropriate box: - [ ] Review Fixes - [ ] Documentation Overhaul - [ ] Feature/Story - Link one or more Engineering Tickets * - [ ] A-Force - [ ] Error in documentation - [ ] Maintenance ## Documentation tickets Link to one or more documentation tickets: - ## Checklist From the below options, select the ones that are applicable: - [ ] Checked for Grammarly suggestions. - [ ] Adhered to the writing checklist. - [ ] Adhered to the media checklist. - [ ] Verified and updated cross-references or added redirect rules. - [ ] Tested the redirect rules on deploy preview. - [ ] Validated the modifications made to the content on the deploy preview. - [ ] Validated the CSS modifications on different screen sizes.
1 parent 5d8d8dd commit 88a2aee

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

website/src/components/custom-search/CustomSearchBar.jsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ import '@site/src/components/custom-search/css/CustomSearch.css';
77
const CustomSearchBar = () => {
88
const [searchType, setSearchType] = useState('');
99

10+
// Identify the user once on mount
11+
useEffect(() => {
12+
if (ExecutionEnvironment.canUseDOM && typeof window.analytics !== 'undefined') {
13+
const user = JSON.parse(localStorage.getItem('user') || '{}');
14+
15+
if (user?.id && user?.email) {
16+
window.analytics.identify(user.id, {
17+
name: user.name,
18+
email: user.email,
19+
plan: user.plan || 'Free',
20+
});
21+
}
22+
23+
// Optional: Enable debug logging
24+
// window.analytics.debug();
25+
}
26+
}, []);
27+
28+
// Trigger search input clicks
1029
useEffect(() => {
1130
if (ExecutionEnvironment.canUseDOM) {
1231
const searchInput = document.querySelector('.DocSearch-Button');
@@ -18,8 +37,10 @@ const CustomSearchBar = () => {
1837
searchInput.click();
1938
setTimeout(() => {
2039
const searchTerm = document.querySelector('.DocSearch-Input');
21-
searchTerm.focus();
22-
searchTerm.click();
40+
if (searchTerm) {
41+
searchTerm.focus();
42+
searchTerm.click();
43+
}
2344
}, 100);
2445
}
2546

@@ -29,11 +50,15 @@ const CustomSearchBar = () => {
2950

3051
const handleClick = (type) => {
3152
setSearchType(type);
32-
if (ExecutionEnvironment.canUseDOM) {
53+
54+
if (ExecutionEnvironment.canUseDOM && typeof window.analytics !== 'undefined') {
3355
const eventName = type === 'ai' ? 'Ask AI Button Click' : 'Search Button Click';
34-
if (typeof window.analytics !== 'undefined') {
35-
window.analytics.track(eventName, { searchType: type });
36-
}
56+
57+
window.analytics.track(eventName, {
58+
searchType: type,
59+
page: window.location.pathname,
60+
timestamp: new Date().toISOString(),
61+
});
3762
}
3863
};
3964

@@ -44,13 +69,13 @@ const CustomSearchBar = () => {
4469
className={`custom-search-option ${searchType === 'ai' ? 'selected' : ''}`}
4570
onClick={() => handleClick('ai')}
4671
>
47-
<img src="/img/ask-ai-robot-icon.svg" alt="Ask AI" className='ai-search-icon'></img> Ask AI
72+
<img src="/img/ask-ai-robot-icon.svg" alt="Ask AI" className="ai-search-icon" /> Ask AI
4873
</div>
4974
<div
5075
className={`custom-search-option ${searchType === 'docs' ? 'selected' : ''}`}
5176
onClick={() => handleClick('docs')}
5277
>
53-
<img src="/img/search-in-docs-icon.svg" alt="Search" className='doc-search-icon'></img> Search
78+
<img src="/img/search-in-docs-icon.svg" alt="Search" className="doc-search-icon" /> Search
5479
</div>
5580
</div>
5681
<AISearchButton />
@@ -61,4 +86,4 @@ const CustomSearchBar = () => {
6186
);
6287
};
6388

64-
export default CustomSearchBar;
89+
export default CustomSearchBar;

0 commit comments

Comments
 (0)