Daniel Kantor commited on
Commit
550c9d4
·
1 Parent(s): 465592a

add search tracking

Browse files
frontend/package.json CHANGED
@@ -3,6 +3,7 @@
3
  "version": "0.1.0",
4
  "private": true,
5
  "dependencies": {
 
6
  "@emotion/react": "^11.13.3",
7
  "@emotion/styled": "^11.13.0",
8
  "@huggingface/hub": "^0.14.0",
 
3
  "version": "0.1.0",
4
  "private": true,
5
  "dependencies": {
6
+ "lodash.debounce": "^4.0.8",
7
  "@emotion/react": "^11.13.3",
8
  "@emotion/styled": "^11.13.0",
9
  "@huggingface/hub": "^0.14.0",
frontend/src/hooks/usePageTracking.js CHANGED
@@ -1,5 +1,14 @@
1
  import { useEffect } from "react";
2
  import { useLocation } from "react-router-dom";
 
 
 
 
 
 
 
 
 
3
 
4
  export function usePageTracking() {
5
  const location = useLocation();
@@ -7,12 +16,12 @@ export function usePageTracking() {
7
  useEffect(() => {
8
  // Send pageview to Google Analytics
9
  if (window.gtag) {
10
- console.debug('sending page view event', location.pathname, location.search, location.hash);
11
- window.gtag("event", "page_view", {
12
  page_path: location.pathname + location.search + location.hash,
13
  page_location: window.location.href,
14
  page_title: document.title
15
- });
 
16
  }
17
  }, [location]);
18
  }
 
1
  import { useEffect } from "react";
2
  import { useLocation } from "react-router-dom";
3
+ import debounce from "lodash.debounce";
4
+
5
+ const debouncedEvent = debounce((eventName, args) => {
6
+ if (window.gtag) {
7
+ console.log('Sending event', eventName, args);
8
+ window.gtag("event", eventName, args);
9
+ }
10
+ }, 500)
11
+
12
 
13
  export function usePageTracking() {
14
  const location = useLocation();
 
16
  useEffect(() => {
17
  // Send pageview to Google Analytics
18
  if (window.gtag) {
19
+ const args = {
 
20
  page_path: location.pathname + location.search + location.hash,
21
  page_location: window.location.href,
22
  page_title: document.title
23
+ }
24
+ debouncedEvent("page_view", args);
25
  }
26
  }, [location]);
27
  }
frontend/src/pages/LeaderboardPage/components/Leaderboard/components/Filters/SearchBar.js CHANGED
@@ -16,6 +16,7 @@ import FilteredModelCount from "./FilteredModelCount";
16
  import { useLeaderboard } from "../../context/LeaderboardContext";
17
  import InfoIconWithTooltip from "../../../../../../components/shared/InfoIconWithTooltip";
18
  import { UI_TOOLTIPS } from "../../constants/tooltips";
 
19
 
20
  export const SearchBarSkeleton = () => (
21
  <Box>
@@ -126,6 +127,7 @@ const SearchBar = ({
126
 
127
  useEffect(() => {
128
  setLocalValue(state.filters.search);
 
129
  }, [state.filters.search]);
130
 
131
  useEffect(() => {
 
16
  import { useLeaderboard } from "../../context/LeaderboardContext";
17
  import InfoIconWithTooltip from "../../../../../../components/shared/InfoIconWithTooltip";
18
  import { UI_TOOLTIPS } from "../../constants/tooltips";
19
+ import { debouncedTrackSearch } from "../../../../../../utils/tracking/search";
20
 
21
  export const SearchBarSkeleton = () => (
22
  <Box>
 
127
 
128
  useEffect(() => {
129
  setLocalValue(state.filters.search);
130
+ debouncedTrackSearch(state.filters.search)
131
  }, [state.filters.search]);
132
 
133
  useEffect(() => {
frontend/src/utils/tracking/search.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import debounce from "lodash.debounce";
2
+
3
+ export const debouncedTrackSearch = debounce((searchTerm) => {
4
+ if (window.gtag && searchTerm) {
5
+ window.gtag("event", "search", {
6
+ search_term: searchTerm
7
+ });
8
+ }
9
+ }, 500);