Skip to content

Commit eeedcb1

Browse files
authored
feat: added metrics for user events (#3237)
* feat: metrics added to tokens redesign * fix: prettier * fix: updated event names * chore: clean up * fix: moved try catch from onSave func
1 parent 56412f2 commit eeedcb1

File tree

6 files changed

+32
-9
lines changed

6 files changed

+32
-9
lines changed

src/authorizations/actions/thunks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ export const updateAuthorization = (authorization: Authorization) => async (
139139
if (resp.status !== 200) {
140140
throw new Error(resp.data.message)
141141
}
142-
142+
event('token.edit.success', {id: authorization.id})
143143
dispatch(getAuthorizations())
144144
dispatch(notify(authorizationUpdateSuccess()))
145145
} catch (e) {
146146
console.error(e)
147+
event('token.edit.failure', {id: authorization.id})
147148
dispatch(notify(authorizationUpdateFailed(authorization.id)))
148149
}
149150
}

src/authorizations/components/redesigned/AllAccessTokenOverlay.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {OverlayContext} from 'src/overlays/components/OverlayController'
2727

2828
// Utils
2929
import {allAccessPermissions} from 'src/authorizations/utils/permissions'
30+
import {event} from 'src/cloud/utils/reporting'
3031

3132
// Selectors
3233
import {getOrg} from 'src/organizations/selectors'
@@ -54,6 +55,7 @@ const AllAccessTokenOverlay: FC<OwnProps> = props => {
5455
}
5556
dispatch(createAuthorization(token))
5657
handleDismiss()
58+
event('token.allAccess.create.success', {meID, name: description})
5759
dispatch(showOverlay('access-token', null, () => dismissOverlay()))
5860
}
5961

src/authorizations/components/redesigned/CustomApiTokenOverlay.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
formatResources,
4747
generateDescription,
4848
} from 'src/authorizations/utils/permissions'
49+
import {event} from 'src/cloud/utils/reporting'
4950

5051
import {showOverlay, dismissOverlay} from 'src/overlays/actions/overlays'
5152

@@ -243,9 +244,11 @@ const CustomApiTokenOverlay: FC<Props> = props => {
243244

244245
try {
245246
await createAuthorization(token)
247+
event('customApiToken.create.success', {description})
246248
showOverlay('access-token', null, () => dismissOverlay())
247249
} catch (e) {
248250
setStatus(ComponentStatus.Disabled)
251+
event('customApiToken.create.failure', {description})
249252
}
250253
}
251254

src/authorizations/components/redesigned/EditTokenOverlay.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {getTelegraf} from 'src/telegrafs/actions/thunks'
3232
// Utills
3333
import {formatPermissionsObj} from 'src/authorizations/utils/permissions'
3434
import _ from 'lodash'
35+
import {event} from 'src/cloud/utils/reporting'
3536
interface OwnProps {
3637
auth: Authorization
3738
onDismissOverlay: () => void
@@ -89,7 +90,7 @@ const EditTokenOverlay: FC<Props> = props => {
8990

9091
const changeToggle = () => {
9192
setStatus(ComponentStatus.Default)
92-
93+
event('tokens.status.updated')
9394
if (togglestatus) {
9495
setToggleStatus(false)
9596
setlabel('inactive')

src/authorizations/components/redesigned/GenerateTokenDropdown.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {getAllResources} from 'src/authorizations/actions/thunks'
1414
import {notify} from 'src/shared/actions/notifications'
1515
import {getResourcesTokensFailure} from 'src/shared/copy/notifications'
1616

17+
// Utils
18+
import {event} from 'src/cloud/utils/reporting'
19+
1720
type GenerateTokenProps = RouteComponentProps
1821
type ReduxProps = ConnectedProps<typeof connector>
1922

@@ -29,14 +32,17 @@ const GenerateTokenDropdown: FC<ReduxProps & GenerateTokenProps> = ({
2932

3033
const handleAllAccess = () => {
3134
showOverlay('add-master-token', null, dismissOverlay)
35+
event('generate_token_dropdown.all_access_overlay.opened')
3236
}
3337

3438
const handleCustomApi = async () => {
3539
try {
3640
await getAllResources()
3741
showOverlay('add-custom-token', null, dismissOverlay)
42+
event('generate_token_dropdown.custom_API_token_overlay.opened')
3843
} catch (e) {
3944
dispatch(notify(getResourcesTokensFailure()))
45+
event('generate_token_dropdown.custom_API_token_overlay.failed')
4046
}
4147
}
4248

src/authorizations/components/redesigned/TokenRow.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040

4141
import {relativeTimestampFormatter} from 'src/shared/utils/relativeTimestampFormatter'
4242
import {incrementCloneName} from 'src/utils/naming'
43+
import {event} from 'src/cloud/utils/reporting'
4344

4445
interface OwnProps {
4546
auth: Authorization
@@ -136,28 +137,37 @@ class TokensRow extends PureComponent<Props> {
136137
this.props.deleteAuthorization(id, description)
137138
}
138139

139-
private handleClone = () => {
140+
private handleClone = async () => {
140141
const {description} = this.props.auth
141-
142142
const allTokenDescriptions = Object.values(this.props.authorizations).map(
143143
auth => auth.description
144144
)
145145

146-
this.props.createAuthorization({
147-
...this.props.auth,
148-
description: incrementCloneName(allTokenDescriptions, description),
149-
})
150-
this.props.showOverlay('access-token', null, () => dismissOverlay())
146+
try {
147+
await this.props.createAuthorization({
148+
...this.props.auth,
149+
description: incrementCloneName(allTokenDescriptions, description),
150+
})
151+
event('token.clone.success', {id: this.props.auth.id, name: description})
152+
this.props.showOverlay('access-token', null, () => dismissOverlay())
153+
} catch {
154+
event('token.clone.failure', {id: this.props.auth.id, name: description})
155+
}
151156
}
152157

153158
private handleClickDescription = () => {
154159
const {onClickDescription, auth} = this.props
160+
event('token_row.edit_overlay.opened')
155161
onClickDescription(auth.id)
156162
}
157163

158164
private handleUpdateName = (value: string) => {
159165
const {auth, updateAuthorization} = this.props
160166
updateAuthorization({...auth, description: value})
167+
event('token.desciption.edited', {
168+
id: this.props.auth.id,
169+
description: value,
170+
})
161171
}
162172
}
163173

0 commit comments

Comments
 (0)