Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new event parameters for purposes of tracking MRR #296

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/components/search/concept-card/concept-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fragment, useState, useEffect, useMemo, forwardRef } from 'react'
import { Fragment, useState, useEffect, useMemo, forwardRef, useCallback } from 'react'
import PropTypes from 'prop-types'
import { Badge, Card, Space, Typography } from 'antd'
import { ExpandOutlined as ViewIcon, LoadingOutlined } from '@ant-design/icons'
Expand All @@ -13,10 +13,17 @@ import './concept-card.css'

const { Text } = Typography

export const ConceptCard = forwardRef(({ index, result, openModalHandler, icon=ViewIcon, className="" }, ref) => {
export const ConceptCard = forwardRef(({
index,
result,
resultRank,
openModalHandler,
icon=ViewIcon,
className=""
}, ref) => {
let { name, type } = result

const [currentTab, setCurrentTab] = useState('overview')
const [currentTab, _setCurrentTab] = useState('overview')
const [studies, setStudies] = useState(null)
const [cdeStudies, setCdeStudies] = useState(null)

Expand Down Expand Up @@ -56,9 +63,25 @@ export const ConceptCard = forwardRef(({ index, result, openModalHandler, icon=V
const tabList = Object.keys(tabs).map(key => tabs[key].content ? ({ key, tab: tabs[key].title }) : null).filter(tab => tab !== null)
const tabContents = Object.keys(tabs).reduce((obj, key) => tabs[key].content ? ({ ...obj, [key]: tabs[key].content }) : obj, {})

const setCurrentTab = useCallback((() => {
let oldTime = Date.now();
return (tabName) => {
const newTime = Date.now();
const elapsed = newTime - oldTime;
_setCurrentTab((currentTab) => {
if (tabName !== currentTab) {
// Make sure we only track events when the tab actually changes.
analyticsEvents.resultCardTabSelected(tabs[tabName].title, tabs[currentTab].title, resultRank, elapsed)
}
return tabName
})
oldTime = newTime;
}
})(), [tabs])

const openModal = (...args) => {
openModalHandler(...args)
analyticsEvents.resultModalOpened(query, result)
analyticsEvents.resultModalOpened(query, result, resultRank)
}

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/search/concept-modal/concept-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const ConceptModalBody = ({ result }) => {
_setCurrentTab((currentTab) => {
if (tabName !== currentTab) {
// Make sure we only track events when the tab actually changes.
analyticsEvents.resultTabSelected(tabs[tabName].title, tabs[currentTab].title, elapsed)
analyticsEvents.resultModalTabSelected(tabs[tabName].title, tabs[currentTab].title, elapsed)
}
return tabName
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const ConceptSearchResults = () => {
key={ result.id }
index={ index }
result={ result }
resultRank={ concepts.indexOf(result) + 1 }
openModalHandler={ () => setSelectedResult(result) }
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const ExpandedResultsSidebar = ({ expanded, setExpanded }) => {
key={result.id}
className={classNames("expanded-result-option-concept-card", result.id === selectedResult?.id && "selected")}
result={result}
resultRank={ concepts.indexOf(result) + 1 }
icon={result.id === selectedResult?.id ? null : ArrowRightOutlined}
openModalHandler={ () => setSelectedResult(result) }
ref={(ref) => cardRefs.current[result.id] = ref}
Expand Down
19 changes: 17 additions & 2 deletions src/contexts/analytics-context/events/search-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function searchExecuted(query, execTime, resultCount, error=null) {
}
});
}
export function resultModalOpened(query, result) {
export function resultModalOpened(query, result, resultRank) {
this.analytics.trackEvent({
category: "ui_interaction",
action: "result_modal_opened",
Expand All @@ -21,11 +21,26 @@ export function resultModalOpened(query, result) {
"search_query": query,
"result_name": result.name,
"result_type": result.type,
// Rank = index in results sorted by score + 1
"result_rank": resultRank,
"additional_search_terms": result.search_terms
}
});
}
export function resultTabSelected(newTabTitle, oldTabTitle, elapsed) {
export function resultCardTabSelected(newTabTitle, oldTabTitle, resultRank, elapsed) {
this.analytics.trackEvent({
category: "ui_interaction",
action: "result_card_tab_selected",
label: newTabTitle,
customParameters: {
"tab_name": newTabTitle,
"previous_tab_name": oldTabTitle,
"result_rank": resultRank,
"time_spent_on_previous_tab": elapsed
}
});
}
export function resultModalTabSelected(newTabTitle, oldTabTitle, elapsed) {
this.analytics.trackEvent({
category: "ui_interaction",
action: "result_tab_selected",
Expand Down
Loading