Skip to content

Commit c79979b

Browse files
committed
implement analytics for label help button & dialogs
1 parent 646c611 commit c79979b

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/components/LabelHelpView/api-key-entry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { styled } from "@material-ui/core/styles"
77
import { useAppConfig } from "../AppConfig"
88
import SaveIcon from "@material-ui/icons/Save"
99
import CircularProgress from "@material-ui/core/CircularProgress"
10+
import usePosthog from "../../utils/use-posthog"
1011

1112
const Title = styled("div")({
1213
fontSize: 18,
@@ -26,11 +27,13 @@ export default () => {
2627
const [verifying, setVerifying] = useState(false)
2728
const [textFieldValue, setTextFieldValue] = useState("")
2829
const [error, setError] = useState("")
30+
const posthog = usePosthog()
31+
2932
return (
3033
<Box paddingTop={8} textAlign="center">
3134
<Title>
3235
To use Label Help, enter your API key. You can{" "}
33-
<a href="https://labelhelp.universaldatatool.com">
36+
<a href="https://labelhelp.universaldatatool.com" onClick={() => posthog.capture('get_api_key_link_clicked')}>
3437
get an API key here
3538
</a>
3639
.
@@ -74,6 +77,7 @@ export default () => {
7477

7578
setVerifying(false)
7679
setInConfig("labelhelp.apikey", textFieldValue)
80+
posthog.capture('save_api_key_button_clicked')
7781
}}
7882
>
7983
{verifying ? (

src/components/LabelHelpView/label-help-dialog-content.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as colors from "@material-ui/core/colors"
1818
import { useActiveDataset } from "../FileContext"
1919
import CircularProgress from "@material-ui/core/CircularProgress"
2020
import { setIn } from "seamless-immutable"
21+
import usePosthog from "../../utils/use-posthog"
2122

2223
const Container = styled("div")({
2324
fontVariantNumeric: "tabular-nums",
@@ -57,6 +58,8 @@ export default () => {
5758
const [labelHelpInfo, setLabelHelpInfo] = useState(dataset.labelHelp || {})
5859
const collabUrl = labelHelpInfo.url || (dataset.labelHelp || {}).url
5960

61+
const posthog = usePosthog()
62+
6063
useEffect(() => {
6164
if (myCredits === null || myCredits === undefined) {
6265
loadMyCredits(dataset)
@@ -173,7 +176,10 @@ export default () => {
173176
<Box>Credits: {usdFormatter.format(myCredits)}</Box>
174177
<Box flexGrow={1} />
175178
<Button
176-
onClick={() => setInConfig("labelhelp.apikey", null)}
179+
onClick={() => {
180+
setInConfig("labelhelp.apikey", null)
181+
posthog.capture('API_key_button_clicked')
182+
}}
177183
variant="outlined"
178184
>
179185
API Key
@@ -183,6 +189,9 @@ export default () => {
183189
style={{ marginLeft: 12 }}
184190
variant="outlined"
185191
href="https://labelhelp.universaldatatool.com#addcredits"
192+
onClick={() => {
193+
posthog.capture('add_credits_button_clicked')
194+
}}
186195
>
187196
Add Credits
188197
</Button>
@@ -216,6 +225,8 @@ export default () => {
216225
url: response.custom_id,
217226
})
218227
)
228+
229+
posthog.capture('start_label_help_button_clicked')
219230
}}
220231
style={{ marginLeft: 12 }}
221232
variant="outlined"

src/components/LabelView/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from "react"
1+
import React, { useEffect, useState } from "react"
22
import LabelErrorBoundary from "../LabelErrorBoundary"
33
import UniversalDataViewer from "../UniversalDataViewer"
44
import Stats from "../Stats"
@@ -46,6 +46,19 @@ export default ({
4646
.map((s) => s.annotation !== undefined && s.annotation !== null)
4747
.filter(Boolean).length / dataset.samples.length
4848
}
49+
50+
useEffect(() => {
51+
if (labelHelpEnabled) {
52+
posthog.capture('label_help_showed')
53+
}
54+
}, [labelHelpEnabled])
55+
56+
useEffect(() => {
57+
if (currentTab === 'labelhelp') {
58+
posthog.capture('label_help_clicked')
59+
}
60+
}, [currentTab])
61+
4962
return singleSampleDataset ? (
5063
<LabelErrorBoundary>
5164
<UniversalDataViewer

0 commit comments

Comments
 (0)