Skip to content

Commit

Permalink
Merge branch 'react-ga4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramin Farhadi authored and Ramin Farhadi committed Jul 16, 2024
2 parents 161977d + 8552303 commit 6c22c83
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import closeIcon from '../assets/xmark-solid.png';
import searchIcon from '../assets/search-white.png';

import './SearchResults.scss';
import { useState } from 'react';
import { useState, useEffect } from 'react';

import ReactGA from "react-ga4"

interface SearchResultsProps {
searchResults: Array<Feature>,
Expand All @@ -14,6 +16,23 @@ interface SearchResultsProps {

export default function SearchResults(props: SearchResultsProps) {
const [searchQuery, setSearchQuery] = useState<string>('');
const [debouncedSearchQuery, setDebouncedSearchQuery] = useState<string>('');

useEffect(() => {
const delaySearchQueryTimeOutId = setTimeout(() => {
setDebouncedSearchQuery(searchQuery);
}, 500);
return () => clearTimeout(delaySearchQueryTimeOutId);
}, [searchQuery, 500])

useEffect(() => {
ReactGA.event({
category: "Map Search",
action: "search",
label: `${debouncedSearchQuery}`,
});
},[debouncedSearchQuery])


return (
<div className='search-control-wrapper rounded'>
Expand Down

0 comments on commit 6c22c83

Please sign in to comment.