Skip to content

Commit 3e83df9

Browse files
committed
Track tag usage
1 parent 664806c commit 3e83df9

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/components/atoms/TagNavigatorListItem.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mdiClose } from '@mdi/js'
55
import { flexCenter } from '../../lib/styled/styleFunctions'
66
import { useRouter } from '../../lib/router'
77
import { useTranslation } from 'react-i18next'
8+
import { useAnalytics, analyticsEvents } from '../../lib/analytics'
89

910
const TagItem = styled.li`
1011
margin-right: 5px;
@@ -54,6 +55,7 @@ const TagNavigatorListItem = ({
5455
}: TagNavigatorListItemProps) => {
5556
const { t } = useTranslation()
5657
const { push } = useRouter()
58+
const { report } = useAnalytics()
5759

5860
return (
5961
<TagItem>
@@ -74,6 +76,7 @@ const TagNavigatorListItem = ({
7476
title={t('tag.removeX', { tag })}
7577
onClick={() => {
7678
removeTagByName(tag)
79+
report(analyticsEvents.removeNoteTag)
7780
}}
7881
>
7982
<Icon path={mdiClose} />

src/components/atoms/TagNavigatorNewTagPopup.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { useEffectOnce } from 'react-use'
2121
import { mdiPound } from '@mdi/js'
2222
import Icon from './Icon'
2323
import { isTagNameValid } from '../../lib/db/utils'
24+
import { useAnalytics, analyticsEvents } from '../../lib/analytics'
2425

2526
const Container = styled.div`
2627
position: fixed;
@@ -81,6 +82,7 @@ const TagNavigatorNewTagPopup = ({
8182
}: TagNavigatorNewTagPopupProps) => {
8283
const [newTagName, setNewTagName] = useState('')
8384
const [menuIndex, setMenuIndex] = useState(0)
85+
const { report } = useAnalytics()
8486

8587
const trimmedNewTagName = useMemo(() => {
8688
return newTagName.trim()
@@ -220,6 +222,7 @@ const TagNavigatorNewTagPopup = ({
220222
appendTagByName(storageTag)
221223
setNewTagName('')
222224
inputRef.current?.focus()
225+
report(analyticsEvents.appendNoteTag)
223226
}}
224227
>
225228
<Icon path={mdiPound} />
@@ -236,6 +239,8 @@ const TagNavigatorNewTagPopup = ({
236239
appendTagByName(trimmedNewTagName)
237240
setNewTagName('')
238241
inputRef.current?.focus()
242+
report(analyticsEvents.appendNoteTag)
243+
report(analyticsEvents.addTag)
239244
}}
240245
>
241246
<span>Create</span>&nbsp;

src/components/molecules/TagListFragment.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useDb } from '../../lib/db'
1010
import { useTranslation } from 'react-i18next'
1111
import { mdiPound, mdiTagMultiple } from '@mdi/js'
1212
import { openContextMenu } from '../../lib/electronOnly'
13+
import { useAnalytics, analyticsEvents } from '../../lib/analytics'
1314

1415
interface TagListFragmentProps {
1516
storage: NoteStorage
@@ -23,6 +24,7 @@ const TagListFragment = ({ storage }: TagListFragmentProps) => {
2324
const { removeTag } = useDb()
2425
const { t } = useTranslation()
2526
const currentPathname = usePathnameWithoutNoteId()
27+
const { report } = useAnalytics()
2628

2729
const tagListNavItemId = getTagListItemId(storage.id)
2830
const tagListIsFolded = !sideNavOpenedItemSet.has(tagListNavItemId)
@@ -59,6 +61,7 @@ const TagListFragment = ({ storage }: TagListFragmentProps) => {
5961
onClose: (value: number | null) => {
6062
if (value === 0) {
6163
removeTag(storageId, tagName)
64+
report(analyticsEvents.removeTag)
6265
}
6366
},
6467
})
@@ -70,7 +73,16 @@ const TagListFragment = ({ storage }: TagListFragmentProps) => {
7073
/>
7174
)
7275
})
73-
}, [storageId, tagMap, push, currentPathname, messageBox, removeTag, t])
76+
}, [
77+
storageId,
78+
tagMap,
79+
push,
80+
currentPathname,
81+
messageBox,
82+
removeTag,
83+
t,
84+
report,
85+
])
7486

7587
if (tagList.length === 0) {
7688
return null

src/lib/analytics.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ export const analyticsEvents = {
8787
createFolder: 'folders.create',
8888
updateUiTheme: 'preferences.updateUiTheme',
8989
updateEditorTheme: 'preferences.updateEditorTheme',
90+
appendNoteTag: 'notes.tags.create',
91+
removeNoteTag: 'notes.tags.destroy',
92+
addTag: 'tags.create',
93+
removeTag: 'tags.destroy',
9094
}

0 commit comments

Comments
 (0)