Skip to content

Commit 4edfa8f

Browse files
authored
Merge pull request #2249 from broadinstitute/ew-pathway-analytics
Log pathway search, click, and hover analytics to Mixpanel (SCP-5989)
2 parents 4303754 + 6d1d50d commit 4edfa8f

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

app/javascript/components/visualization/Pathway.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Popover, OverlayTrigger } from 'react-bootstrap'
33
import { manageDrawPathway, writeLoadingIndicator } from '~/lib/pathway-expression'
44
import { getIdentifierForAnnotation, naturalSort } from '~/lib/cluster-utils'
55
import { round } from '~/lib/metrics-perf'
6+
import { log } from '~/lib/metrics-api'
67

78
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
89
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons'
@@ -80,6 +81,17 @@ function handleGeneNodeHover(event, geneName) {
8081
node.setAttribute('data-toggle', 'tooltip')
8182
node.setAttribute('data-html', 'true')
8283
node.setAttribute('data-original-title', content)
84+
85+
const pathwayId = window.Ideogram.pathwayJson.pathway.id
86+
const pathwayName = window.Ideogram.pathwayJson.pathway.name
87+
88+
log('pathway-node-tooltip', {
89+
pathway: pathwayId,
90+
pathwayName,
91+
name: geneName,
92+
nodeType: 'gene'
93+
})
94+
8395
return ''
8496
}
8597

@@ -141,6 +153,14 @@ export default function Pathway({
141153
/** Upon clicking a pathway node, show new pathway and expression overlay */
142154
function handlePathwayNodeClick(event, pathwayId) {
143155
queryFn([pathwayId])
156+
157+
const pathwayName = window.Ideogram.pathwayJson.pathway.name
158+
159+
log('pathway-node-click', {
160+
pathway: pathwayId,
161+
pathwayName,
162+
nodeType: 'pathway'
163+
})
144164
}
145165

146166
const dimensionString = JSON.stringify(dimensions)

app/javascript/lib/search-metrics.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,16 @@ function detectSearchedGenesElsewhere(searchedGenes) {
202202

203203
/** log a search from the study explore tab */
204204
export function logStudyGeneSearch(genes, trigger, speciesList, otherProps) {
205+
let searchType = 'gene'
206+
207+
const pathwayRegEx = /^WP\d+$/
208+
if (genes.length === 1 && pathwayRegEx.test(genes[0])) {
209+
searchType = 'pathway'
210+
}
211+
205212
// Properties logged for all gene searches from Study Overview
206213
const logProps = {
207-
type: 'gene',
214+
type: searchType,
208215
context: 'study',
209216
genes,
210217
numGenes: genes.length,

test/js/explore/study-gene-keyword.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import '@testing-library/jest-dom/extend-expect'
55

66
import StudyGeneField, { getIsInvalidQuery, getIsEligibleForPathwayExplore } from 'components/explore/StudyGeneField'
77
import * as UserProvider from '~/providers/UserProvider'
8+
import { logStudyGeneSearch } from '~/lib/search-metrics'
9+
import * as MetricsApi from '~/lib/metrics-api'
810
import { interestingNames, interactionCacheCsn1s1 } from './../visualization/pathway.test-data'
911

1012
describe('Search query display text', () => {
@@ -121,5 +123,34 @@ describe('Search query display text', () => {
121123
expect(isHumanGroupAnnotationEligible).toBe(true)
122124
})
123125

126+
it('distinguishes pathway from gene search types in analytics logging', async () => {
127+
const fakeLog = jest.spyOn(MetricsApi, 'log')
128+
fakeLog.mockImplementation(() => { })
129+
130+
let queries = ['PTEN']
131+
const trigger = 'click'
132+
const speciesList = ['Homo sapiens']
133+
134+
logStudyGeneSearch(queries, trigger, speciesList)
135+
136+
expect(fakeLog).toHaveBeenCalledWith(
137+
'search',
138+
expect.objectContaining({
139+
type: 'gene'
140+
})
141+
)
142+
143+
queries = ['WP1234']
144+
145+
logStudyGeneSearch(queries, trigger, speciesList)
146+
147+
expect(fakeLog).toHaveBeenCalledWith(
148+
'search',
149+
expect.objectContaining({
150+
type: 'pathway'
151+
})
152+
)
153+
154+
})
124155
})
125156

0 commit comments

Comments
 (0)