From 0e57db3c4dcefe9499fe672c53003a5c1ea58ca5 Mon Sep 17 00:00:00 2001 From: rushtong Date: Thu, 25 Jul 2024 07:57:33 -0400 Subject: [PATCH 1/2] feat: log data library page views --- src/libs/events.js | 11 ++++++++++- src/pages/DatasetSearch.jsx | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/libs/events.js b/src/libs/events.js index 594fe4986..074643f98 100644 --- a/src/libs/events.js +++ b/src/libs/events.js @@ -1,8 +1,17 @@ +/* + * NOTE: See the Mixpanel guide in the terra-ui GitHub Wiki for more details: + * https://github.com/DataBiosphere/terra-ui/wiki/Mixpanel + */ const eventList = { userRegister: 'user:register', userSignIn: 'user:signin', pageView: 'page:view', + dataLibrary: 'page:view:dataLibrary', + dataLibraryBrand: (brand) => { + const cleanKey = brand.replaceAll('/', ''); + return `page:view:dataLibrary:${cleanKey}`; + } }; -export default eventList; \ No newline at end of file +export default eventList; diff --git a/src/pages/DatasetSearch.jsx b/src/pages/DatasetSearch.jsx index 12a392192..ce073e7b9 100644 --- a/src/pages/DatasetSearch.jsx +++ b/src/pages/DatasetSearch.jsx @@ -18,6 +18,8 @@ import homeIcon from '../images/icon_dataset_.png'; import { Storage } from '../libs/storage'; import { Box, CircularProgress } from '@mui/material'; import { toLower } from 'lodash'; +import {Metrics} from '../libs/ajax/Metrics'; +import eventList from '../libs/events'; const assembleFullQuery = (isSigningOfficial, isInstitutionQuery, subQuery) => { const queryChunks = [ @@ -246,6 +248,16 @@ export const DatasetSearch = (props) => { const hasChangedPage = query !== queryState; + useEffect(() => { + const init = async () => { + await Metrics.identify(Storage.getAnonymousId()); + key === '/datalibrary' ? + await Metrics.captureEvent(eventList.dataLibrary) : + await Metrics.captureEvent(eventList.dataLibraryBrand(key)); + }; + init(); + }, [key]); + useEffect(() => { const init = async () => { if (loading || hasChangedPage) { From 193cd9344da053c9c3ed32b92842547b66e1160e Mon Sep 17 00:00:00 2001 From: rushtong Date: Thu, 25 Jul 2024 09:39:15 -0400 Subject: [PATCH 2/2] feat: remove extraneous identify call --- src/pages/DatasetSearch.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/DatasetSearch.jsx b/src/pages/DatasetSearch.jsx index ce073e7b9..09ec59be0 100644 --- a/src/pages/DatasetSearch.jsx +++ b/src/pages/DatasetSearch.jsx @@ -250,7 +250,6 @@ export const DatasetSearch = (props) => { useEffect(() => { const init = async () => { - await Metrics.identify(Storage.getAnonymousId()); key === '/datalibrary' ? await Metrics.captureEvent(eventList.dataLibrary) : await Metrics.captureEvent(eventList.dataLibraryBrand(key));