Skip to content

Commit 3fd2e98

Browse files
committed
feat: log most user interactions to firebase analytics
1 parent 1906d69 commit 3fd2e98

File tree

7 files changed

+49
-12
lines changed

7 files changed

+49
-12
lines changed

src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2-
import { Drawer, Header } from '@ugrc/utah-design-system';
2+
import { Drawer, Header, useFirebaseAnalytics } from '@ugrc/utah-design-system';
33
import { useLocalStorage } from '@ugrc/utilities/hooks';
44
import { useState } from 'react';
55
import { useOverlayTrigger } from 'react-aria';
@@ -31,7 +31,9 @@ export default function App() {
3131

3232
const clearIdentify = () => setIdentifyGraphic(null);
3333

34+
const logEvent = useFirebaseAnalytics();
3435
const onFeatureIdentify = (graphic: __esri.Graphic | null) => {
36+
logEvent('identify');
3537
if (graphic) {
3638
trayState.open();
3739
}

src/components/Feedback.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
Button,
55
TextArea,
66
TextField,
7+
useFirebaseAnalytics,
78
useFirebaseFunctions,
89
} from '@ugrc/utah-design-system';
910
import { httpsCallable } from 'firebase/functions';
@@ -29,7 +30,9 @@ export default function Feedback({
2930
FeedbackResponse
3031
>(functions, 'submitFeedback');
3132

33+
const logEvent = useFirebaseAnalytics();
3234
const submitFeedback = async (data: FeedbackSubmission) => {
35+
logEvent('submit_feedback');
3336
const response = await submitFeedbackCallable(data);
3437
if (!response.data.success) {
3538
throw new Error(response.data.errorMessage);

src/components/Filter.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Checkbox, Spinner, Switch } from '@ugrc/utah-design-system';
1+
import {
2+
Checkbox,
3+
Spinner,
4+
Switch,
5+
useFirebaseAnalytics,
6+
} from '@ugrc/utah-design-system';
27
import type { ClassOrders } from '../context/FirebaseRemoteConfigsProvider';
38
import { useFilter } from '../hooks/useFilter';
49
import useRemoteConfigs from '../hooks/useRemoteConfigs';
@@ -12,6 +17,8 @@ export default function Filter() {
1217
const isRouteTypes = state.selectedFilterType === 'routeTypes';
1318
const getConfig = useRemoteConfigs();
1419

20+
const logEvent = useFirebaseAnalytics();
21+
1522
if (state.routeTypes.rendererClasses.length === 0 || !getConfig) {
1623
return (
1724
<div className="flex h-80 w-full items-center justify-center">
@@ -55,11 +62,12 @@ export default function Filter() {
5562
<Switch
5663
className="mb-3"
5764
isSelected={isRouteTypes}
58-
onChange={() =>
65+
onChange={() => {
66+
logEvent('toggle_filter_type');
5967
dispatch({
6068
type: 'TOGGLE_FILTER_TYPE',
61-
})
62-
}
69+
});
70+
}}
6371
>
6472
<h2>
6573
{isRouteTypes ? layerNames.routeTypes : layerNames.trafficStress}
@@ -71,12 +79,13 @@ export default function Filter() {
7179
{getRendererClassCheckboxes('routeTypes')}
7280
<Checkbox
7381
isSelected={state.layerToggles.otherLinks}
74-
onChange={() =>
82+
onChange={() => {
83+
logEvent('toggle_other_links');
7584
dispatch({
7685
type: 'TOGGLE_LAYER',
7786
payload: { layerKey: 'otherLinks' },
78-
})
79-
}
87+
});
88+
}}
8089
>
8190
<LegendSwatch symbol={state.symbols.otherLinks} />
8291
<Label>Other Links</Label>

src/components/Identify.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@arcgis/map-components/components/arcgis-feature';
2-
import { Button } from '@ugrc/utah-design-system';
2+
import { Button, useFirebaseAnalytics } from '@ugrc/utah-design-system';
33
import { CircleX } from 'lucide-react';
44
import { useEffect, useRef, useState } from 'react';
55
import Feedback from './Feedback';
@@ -14,6 +14,8 @@ export default function Identify({ graphic, clear }: IdentifyProps) {
1414
const [showFeedback, setShowFeedback] = useState(false);
1515
const featureComponentRef = useRef<HTMLArcgisFeatureElement>(null);
1616

17+
const logEvent = useFirebaseAnalytics();
18+
1719
useEffect(() => {
1820
setShowFeedback(false);
1921
}, [graphic]);
@@ -38,7 +40,13 @@ export default function Identify({ graphic, clear }: IdentifyProps) {
3840
graphic={featureComponentRef.current!.graphic!}
3941
/>
4042
) : (
41-
<Button className="w-full" onPress={() => setShowFeedback(true)}>
43+
<Button
44+
className="w-full"
45+
onPress={() => {
46+
logEvent('show_feature_feedback');
47+
setShowFeedback(true);
48+
}}
49+
>
4250
Give feedback about this road or trail
4351
</Button>
4452
)}

src/components/MapContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BusyBar } from '@ugrc/utah-design-system';
1+
import { BusyBar, useFirebaseAnalytics } from '@ugrc/utah-design-system';
22
import { useGraphicManager, useViewLoading } from '@ugrc/utilities/hooks';
33
import { useEffect, useRef, useState } from 'react';
44
import { createPortal } from 'react-dom';
@@ -39,6 +39,8 @@ export const MapContainer = ({
3939
const [center, setCenter] = useState<number[] | null>(null);
4040
const showFeedback = genericFeedbackPoint !== null;
4141

42+
const logEvent = useFirebaseAnalytics();
43+
4244
// Set up the map
4345
const { mapView, layers, highlightHandle } = useMapSetup(
4446
mapNode,
@@ -83,6 +85,7 @@ export const MapContainer = ({
8385

8486
// Handle feedback button click
8587
const handleFeedbackClick = () => {
88+
logEvent('generic_feedback_button_click');
8689
if (showFeedback) {
8790
setGenericFeedbackPoint(null);
8891
} else {
@@ -102,6 +105,7 @@ export const MapContainer = ({
102105

103106
// Handle zoom to location button click
104107
const handleZoomToLocation = () => {
108+
logEvent('zoom_to_location');
105109
getCoarseLocation().then((location) => {
106110
if (location && mapView.current) {
107111
mapView.current.goTo({

src/components/RendererClassCheckbox.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Checkbox } from '@ugrc/utah-design-system';
1+
import { Checkbox, useFirebaseAnalytics } from '@ugrc/utah-design-system';
22
import { useFilter } from '../hooks/useFilter';
33
import type { LayersWithRenderClassesKeys } from '../shared';
44
import Label from './Label';
@@ -17,7 +17,13 @@ export default function RendererClassCheckbox({
1717
}: RendererClassCheckboxProps) {
1818
const { state, dispatch } = useFilter();
1919

20+
const logEvent = useFirebaseAnalytics();
21+
2022
const handleCheckboxChange = () => {
23+
logEvent('filter_renderer_class', {
24+
rendererClass: rendererClass.label,
25+
layerKey,
26+
});
2127
dispatch({
2228
type: 'TOGGLE_RENDERER_CLASS',
2329
payload: {

src/hooks/useMapSetup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import WebMap from '@arcgis/core/WebMap';
44
import BasemapToggle from '@arcgis/core/widgets/BasemapToggle.js';
55
import Home from '@arcgis/core/widgets/Home';
66
import Track from '@arcgis/core/widgets/Track';
7+
import { useFirebaseAnalytics } from '@ugrc/utah-design-system';
78
import debounce from 'lodash.debounce';
89
import { useEffect, useRef } from 'react';
910
import { getCoarseLocation, INITIAL_MAP_ZOOM } from '../components/mapUtils';
@@ -38,6 +39,8 @@ export function useMapSetup(
3839
const highlightHandle = useRef<__esri.Handle>(null);
3940
const { dispatch } = useFilter();
4041

42+
const logEvent = useFirebaseAnalytics();
43+
4144
// set up map
4245
useEffect(() => {
4346
if (!mapNodeRef.current || mapIsInitialized.current || !getConfig) {
@@ -166,7 +169,9 @@ export function useMapSetup(
166169
await view.when();
167170

168171
const homeWidget = new Home({ view });
172+
homeWidget.on('go', () => logEvent('home_button_click'));
169173
const trackWidget = new Track({ view });
174+
trackWidget.on('track', () => logEvent('track_button_click'));
170175
view.ui.add(homeWidget, 'top-right');
171176
view.ui.add(trackWidget, 'top-right');
172177
view.ui.add(zoomButtonRef.current!, 'top-right');

0 commit comments

Comments
 (0)