Skip to content

Commit ae30eab

Browse files
authored
feat: add ui eventing for multi-org phase 2 (#6415)
* chore: eventing for multi-org phase 2 * fix: prettier * fix: prettier * chore: update naming convention for events * chore: address pr comments * chore: alphabetize multi org events * chore: add an account name selector * fix: prettier * chore: update eventing name * fix: remove org failure from event
1 parent 4cba73b commit ae30eab

File tree

8 files changed

+164
-23
lines changed

8 files changed

+164
-23
lines changed

src/identity/components/GlobalHeader/GlobalHeaderDropdown/CreateOrganization/CreateOrganizationOverlay.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,29 @@ import {getOrgCreationAllowancesThunk} from 'src/identity/allowances/actions/thu
9292
import {generateProviderMap} from 'src/identity/components/GlobalHeader/GlobalHeaderDropdown/CreateOrganization/utils/generateProviderMap'
9393
import {SafeBlankLink} from 'src/utils/SafeBlankLink'
9494

95+
// Eventing
96+
import {event} from 'src/cloud/utils/reporting'
97+
import {
98+
CreateOrgOverlayEvent,
99+
multiOrgTag,
100+
} from 'src/identity/events/multiOrgEvents'
101+
95102
const switchToNewOrgButtonStyle = {
96103
color: 'black',
97104
textDecoration: 'underline',
98105
cursor: 'pointer',
99106
}
100107

101-
const SwitchToNewOrgButton = (url: string): JSX.Element => {
108+
const SwitchToNewOrgButton = (
109+
url: string,
110+
handleClick: () => void
111+
): JSX.Element => {
102112
return (
103113
<a
104114
href={url}
105115
data-testid="go-to-new-org--link"
106116
style={switchToNewOrgButtonStyle}
117+
onClick={handleClick}
107118
>
108119
Switch to new org.
109120
</a>
@@ -205,13 +216,15 @@ export const CreateOrganizationOverlay: FC = () => {
205216
retrieveClusters()
206217
}, [])
207218

208-
// Event Handlers
209-
const createNewOrgPopup = (newOrg: CreatedOrg) => {
219+
const createNewOrgPopup = (
220+
newOrg: CreatedOrg,
221+
handleSwitchToNewOrgEvent: () => void
222+
) => {
210223
const newOrgUrl = `${CLOUD_URL}/orgs/${newOrg.id}`
211224

212225
const switchToOrgLink =
213226
newOrg.provisioningStatus === 'provisioned'
214-
? () => SwitchToNewOrgButton(newOrgUrl)
227+
? () => SwitchToNewOrgButton(newOrgUrl, handleSwitchToNewOrgEvent)
215228
: null
216229

217230
dispatch(notify(quartzOrgCreateSuccess(newOrg.name, switchToOrgLink)))
@@ -233,12 +246,26 @@ export const CreateOrganizationOverlay: FC = () => {
233246
orgCreationAllowed => {
234247
dispatch(getQuartzOrganizationsThunk(currentAccountId))
235248

236-
createNewOrgPopup(newOrg)
249+
// Event Handlers
250+
const handleSwitchToNewOrgEvent = () => {
251+
event(CreateOrgOverlayEvent.SwitchToNewOrg, multiOrgTag, {
252+
newOrgID: newOrg.id,
253+
newOrgName: newOrg.name,
254+
oldOrgID: currentOrgId,
255+
})
256+
}
257+
createNewOrgPopup(newOrg, handleSwitchToNewOrgEvent)
237258

238259
if (!orgCreationAllowed) {
239260
dispatch(notify(quartzOrgQuotaReached()))
240261
}
241262

263+
event(CreateOrgOverlayEvent.OrgCreated, multiOrgTag, {
264+
newOrgID: newOrg.id,
265+
newOrgName: newOrg.name,
266+
oldOrgID: currentOrgId,
267+
})
268+
242269
history.push(`/orgs/${currentOrgId}/accounts/orglist`)
243270

244271
onClose()

src/identity/components/GlobalHeader/GlobalHeaderDropdown/CreateOrganization/MenuItem.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
// Libraries
22
import React, {FC} from 'react'
3+
import {useDispatch, useSelector} from 'react-redux'
34
import {
45
AlignItems,
56
Dropdown,
67
FlexBox,
78
Icon,
89
IconFont,
910
} from '@influxdata/clockface'
10-
import {useDispatch} from 'react-redux'
1111

1212
// Components
1313
import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays'
1414

15+
// Selectors
16+
import {selectCurrentAccount, selectUser} from 'src/identity/selectors'
17+
18+
// Eventing
19+
import {HeaderNavEvent, multiOrgTag} from 'src/identity/events/multiOrgEvents'
20+
import {event} from 'src/cloud/utils/reporting'
21+
1522
export const CreateOrganizationMenuItem: FC = () => {
1623
const dispatch = useDispatch()
24+
const user = useSelector(selectUser)
25+
const account = useSelector(selectCurrentAccount)
26+
1727
const handleCreateOrg = () => {
28+
event(HeaderNavEvent.CreateOrgClick, multiOrgTag, {
29+
userId: user.id,
30+
accountId: account.id,
31+
accountName: account.name,
32+
accountType: account.type,
33+
})
1834
dispatch(
1935
showOverlay('create-organization', null, () => dispatch(dismissOverlay()))
2036
)

src/identity/components/GlobalHeader/OrgDropdown.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ import {isFlagEnabled} from 'src/shared/utils/featureFlag'
3333

3434
// Selectors
3535
import {
36+
selectCurrentAccount,
3637
selectOrgCreationAllowance,
3738
selectOrgCreationAllowanceStatus,
3839
selectOrgCreationAvailableUpgrade,
40+
selectUser,
3941
} from 'src/identity/selectors'
4042
import {CreateOrganizationMenuItem} from 'src/identity/components/GlobalHeader/GlobalHeaderDropdown/CreateOrganization/MenuItem'
4143
import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays'
@@ -56,10 +58,18 @@ export const OrgDropdown: FC<Props> = ({activeOrg, orgsList}) => {
5658
const orgCreationAllowanceStatus = useSelector(
5759
selectOrgCreationAllowanceStatus
5860
)
61+
const user = useSelector(selectUser)
62+
const account = useSelector(selectCurrentAccount)
5963

6064
const dispatch = useDispatch()
6165

6266
const openMarketoOverlay = () => {
67+
event(HeaderNavEvent.UpgradeButtonClick, multiOrgTag, {
68+
accountId: account.id,
69+
accountName: account.name,
70+
accountType: account.type,
71+
userId: user.id,
72+
})
6373
dispatch(
6474
showOverlay('marketo-upgrade-account-overlay', null, () =>
6575
dispatch(dismissOverlay())

src/identity/components/MarketoAccountUpgradeOverlay.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ import {
1414
import {OverlayContext} from 'src/overlays/components/OverlayController'
1515

1616
// Selectors
17-
import {selectCurrentAccountId, selectUser} from 'src/identity/selectors'
17+
import {
18+
selectCurrentAccountId,
19+
selectCurrentAccountName,
20+
selectCurrentAccountType,
21+
selectUser,
22+
} from 'src/identity/selectors'
1823

1924
// Error Reporting
2025
import {reportErrorThroughHoneyBadger} from 'src/shared/utils/errors'
@@ -29,6 +34,13 @@ import {
2934
// Utils
3035
import {notify} from 'src/shared/actions/notifications'
3136

37+
// Eventing
38+
import {
39+
AccountUpgradeOverlay,
40+
multiOrgTag,
41+
} from 'src/identity/events/multiOrgEvents'
42+
import {event} from 'src/cloud/utils/reporting'
43+
3244
// Styles
3345
import './MarketoAccountUpgradeOverlay.scss'
3446

@@ -70,13 +82,28 @@ interface MarketoFormElement extends Element {
7082
}
7183

7284
// If marketo isn't working, still need the user to have some means of contacting sales.
73-
const SalesFormLink = (): JSX.Element => {
85+
const SalesFormLink = () => {
86+
const user = useSelector(selectUser)
87+
const accountId = useSelector(selectCurrentAccountId)
88+
const accountName = useSelector(selectCurrentAccountName)
89+
const accountType = useSelector(selectCurrentAccountType)
90+
91+
const handleEventing = () => {
92+
event(AccountUpgradeOverlay.SalesFormLinkClick, multiOrgTag, {
93+
userId: user.id,
94+
accountId,
95+
accountName,
96+
accountType,
97+
})
98+
}
99+
74100
return (
75101
<a
76102
data-testid="use-sales-form--link"
77103
href={BACKUP_CONTACT_SALES_LINK}
78104
target="_blank"
79105
style={popupLinkStyle}
106+
onClick={handleEventing}
80107
>
81108
Click here to contact sales.
82109
</a>
@@ -89,6 +116,8 @@ export const MarketoAccountUpgradeOverlay: FC = () => {
89116

90117
const user = useSelector(selectUser)
91118
const accountId = useSelector(selectCurrentAccountId)
119+
const accountName = useSelector(selectCurrentAccountName)
120+
const accountType = useSelector(selectCurrentAccountType)
92121

93122
const [scriptHasLoaded, setScriptHasLoaded] = useState(false)
94123
const [formHasLoaded, setFormHasLoaded] = useState(false)
@@ -99,7 +128,6 @@ export const MarketoAccountUpgradeOverlay: FC = () => {
99128
delete window.MktoForms2
100129
onClose()
101130
}
102-
103131
const handleComment = (evt: React.ChangeEvent<HTMLInputElement>) => {
104132
if (window.MktoForms2.getForm) {
105133
try {
@@ -137,6 +165,12 @@ export const MarketoAccountUpgradeOverlay: FC = () => {
137165
try {
138166
window.MktoForms2.getForm(MARKETO_FORM_ID).submit()
139167
dispatch(notify(marketoFormSubmitSuccess()))
168+
event(AccountUpgradeOverlay.MarketoAccountUpgrade, multiOrgTag, {
169+
accountId,
170+
accountName,
171+
accountType,
172+
userId: user.id,
173+
})
140174
onClose()
141175
} catch (err) {
142176
handleError(MarketoError.FormSubmitError, err)

src/identity/components/OrganizationListTab/OrgBannerPanel.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Libraries
22
import React, {FC} from 'react'
3-
import {useDispatch} from 'react-redux'
3+
import {useDispatch, useSelector} from 'react-redux'
44
import {useHistory} from 'react-router-dom'
55
import {BannerPanel, FlexBox, Gradients, IconFont} from '@influxdata/clockface'
66

@@ -13,6 +13,16 @@ import {availableUpgrade} from 'src/client/unityRoutes'
1313
// Utils
1414
import {dismissOverlay, showOverlay} from 'src/overlays/actions/overlays'
1515

16+
// Selectors
17+
import {
18+
selectCurrentAccountId,
19+
selectCurrentAccountName,
20+
} from 'src/identity/selectors'
21+
22+
// Eventing
23+
import {multiOrgTag, OrgListEvent} from 'src/identity/events/multiOrgEvents'
24+
import {event} from 'src/cloud/utils/reporting'
25+
1626
interface OrgAllowance {
1727
availableUpgrade: availableUpgrade
1828
isAtOrgLimit: boolean
@@ -28,8 +38,16 @@ export const OrgBannerPanel: FC<OrgAllowance> = ({
2838
}) => {
2939
const dispatch = useDispatch()
3040
const history = useHistory()
41+
const accountId = useSelector(selectCurrentAccountId)
42+
const accountName = useSelector(selectCurrentAccountName)
3143

3244
const handleUpgradeAccount = () => {
45+
event(OrgListEvent.UpgradeAccount, multiOrgTag, {
46+
availableUpgrade,
47+
accountId,
48+
accountName,
49+
})
50+
3351
if (availableUpgrade === 'pay_as_you_go') {
3452
history.push(`/checkout`)
3553
} else {

src/identity/events/multiOrgEvents.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,43 @@ export const multiOrgTag = {
22
initiative: 'multiOrg',
33
}
44

5+
export enum AccountUpgradeOverlay {
6+
MarketoAccountUpgrade = 'userProfile.marketoAccountUpgrade.formSubmitted',
7+
SalesFormLinkClick = 'userProfile.marketoAccountUpgrade.salesFormLinkClicked',
8+
}
9+
10+
export enum CreateOrgOverlayEvent {
11+
OrgCreated = 'headerNav.createOrgOverlay.orgCreated',
12+
SwitchToNewOrg = 'headerNav.createOrgOverlay.switchedToNewOrg',
13+
}
14+
15+
export enum DeleteOrgOverlay {
16+
DeleteOrg = 'userProfile.orgProfileTab.orgDeleted',
17+
}
18+
519
export enum HeaderNavEvent {
620
AccountDropdownClick = 'headerNav.accountDropdown.clicked',
721
AccountSwitch = 'headerNav.accountDropdown.accountSwitched',
822

23+
CreateOrgClick = 'headerNav.createOrg.clicked',
924
OrgDropdownClick = 'headerNav.orgDropdown.clicked',
1025
OrgSwitch = 'headerNav.orgDropdown.orgSwitched',
1126

27+
UpgradeButtonClick = 'headerNav.upgradeButton.clicked',
1228
UserAvatarClick = 'headerNav.userAvatarIcon.clicked',
1329
UserProfileClick = 'headerNav.userAvatarProfile.clicked',
1430
UserLogoutClick = 'headerNav.userAvatarLogOut.clicked',
1531
}
1632

17-
export enum UserProfileEvent {
18-
DefaultAccountChange = 'userProfile.defaultAccountDropdown.defaultAccountChanged',
19-
DefaultOrgChange = 'userProfile.defaultOrgDropdown.defaultOrgChanged',
20-
}
21-
22-
export enum UserProfileEventPrefix {
23-
Default = 'userProfile.default',
24-
Account = 'Account',
25-
Organization = 'Org',
26-
}
27-
2833
export enum MainMenuEventPrefix {
34+
ChangeDefaultAccount = 'userProfile.defaultAccountDropdown',
35+
ChangeDefaultOrg = 'userProfile.defaultOrgDropdown',
2936
SwitchOrg = 'headerNav.org',
3037
SwitchAccount = 'headerNav.account',
38+
}
3139

32-
ChangeDefaultOrg = 'userProfile.defaultOrgDropdown',
33-
ChangeDefaultAccount = 'userProfile.defaultAccountDropdown',
40+
export enum OrgListEvent {
41+
UpgradeAccount = 'accountSettings.orgsTab.upgradeBannerClicked',
3442
}
3543

3644
export enum TypeAheadEventPrefix {
@@ -40,3 +48,14 @@ export enum TypeAheadEventPrefix {
4048
UserProfileSearchAccount = 'userProfile.defaultAccountDropdown',
4149
UserProfileSearchOrg = 'userProfile.defaultOrgDropdown',
4250
}
51+
52+
export enum UserProfileEvent {
53+
DefaultAccountChange = 'userProfile.defaultAccountDropdown.defaultAccountChanged',
54+
DefaultOrgChange = 'userProfile.defaultOrgDropdown.defaultOrgChanged',
55+
}
56+
57+
export enum UserProfileEventPrefix {
58+
Account = 'Account',
59+
Default = 'userProfile.default',
60+
Organization = 'Org',
61+
}

src/identity/selectors/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const selectCurrentAccountId = (
1414
return state.identity.currentIdentity.account.id
1515
}
1616

17+
export const selectCurrentAccountName = (
18+
state: AppState
19+
): AppState['identity']['currentIdentity']['account']['name'] => {
20+
return state.identity.currentIdentity.account.name
21+
}
22+
1723
export const selectCurrentAccountType = (
1824
state: AppState
1925
): AppState['identity']['currentIdentity']['account']['type'] => {

src/organizations/components/OrgProfileTab/DeletePaidOrgOverlay.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import {notify} from 'src/shared/actions/notifications'
3939
import {OverlayContext} from 'src/overlays/components/OverlayController'
4040
import {reportErrorThroughHoneyBadger} from 'src/shared/utils/errors'
4141

42+
// Eventing
43+
import {DeleteOrgOverlay, multiOrgTag} from 'src/identity/events/multiOrgEvents'
44+
import {event} from 'src/cloud/utils/reporting'
45+
4246
// Styles
4347
import './DeletePaidOrgOverlay.scss'
4448

@@ -107,6 +111,13 @@ export const DeletePaidOrgOverlay: FC = () => {
107111
.then(() => {
108112
clearTimeout(responseTimer)
109113
dispatch(notify(deleteOrgSuccess(org.name, account.name)))
114+
event(DeleteOrgOverlay.DeleteOrg, multiOrgTag, {
115+
accountId: account.id,
116+
accoutnName: account.name,
117+
accountType: account.type,
118+
orgName: org.name,
119+
userId: org.id,
120+
})
110121
setTimeout(() => {
111122
onClose()
112123
window.location.href = CLOUD_URL

0 commit comments

Comments
 (0)