Skip to content

Commit 8288de2

Browse files
committed
chore: GA events added
1 parent b757137 commit 8288de2

File tree

9 files changed

+118
-39
lines changed

9 files changed

+118
-39
lines changed

src/components/AppSelector/AppSelector.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616

1717
import { useRef, useState } from 'react'
18-
import ReactGA from 'react-ga4'
1918
import { ActionMeta } from 'react-select'
2019

2120
import {
2221
ContextSwitcher,
22+
handleAnalyticsEvent,
2323
RecentlyVisitedOptions,
2424
ResourceKindType,
2525
SelectPickerOptionType,
@@ -29,8 +29,7 @@ import {
2929
} from '@devtron-labs/devtron-fe-common-lib'
3030

3131
import { AppSelectorType } from './AppSelector.types'
32-
import { appListOptions } from './AppSelectorUtil'
33-
import { APP_DETAILS_GA_EVENTS } from './constants'
32+
import { appListOptions, getAppSelectGAEvent } from './AppSelectorUtil'
3433

3534
const AppSelector = ({ onChange, appId, appName, isJobView }: AppSelectorType) => {
3635
const abortControllerRef = useRef<AbortController>(new AbortController())
@@ -72,13 +71,10 @@ const AppSelector = ({ onChange, appId, appName, isJobView }: AppSelectorType) =
7271

7372
onChange(selectedOption, actionMeta)
7473

75-
if (!isJobView) {
76-
ReactGA.event(
77-
selectedOption.isRecentlyVisited
78-
? APP_DETAILS_GA_EVENTS.RecentlyVisitedApps
79-
: APP_DETAILS_GA_EVENTS.SearchesAppClicked,
80-
)
81-
}
74+
handleAnalyticsEvent({
75+
category: isJobView ? 'Job Selector' : 'App Selector',
76+
action: getAppSelectGAEvent(selectedOption, isJobView),
77+
})
8278
}
8379

8480
return (

src/components/AppSelector/AppSelectorUtil.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525

2626
import { getAppListMin } from '../../services/service'
2727
import { AppListOptionsTypes } from './AppSelector.types'
28-
import { getMinCharSearchPlaceholderGroup } from './constants'
28+
import { appSelectorGAEvents, getMinCharSearchPlaceholderGroup } from './constants'
2929

3030
let timeoutId
3131

@@ -87,3 +87,16 @@ export const appListOptions = ({
8787
}, 300)
8888
})
8989
}
90+
91+
export const getAppSelectGAEvent = (selectedOption: RecentlyVisitedOptions, isJobView) => {
92+
if (isJobView) {
93+
if (selectedOption.isRecentlyVisited) {
94+
return appSelectorGAEvents.JOB_SWITCH_RECENTLY_VISITED_CLICKED
95+
}
96+
return appSelectorGAEvents.JOB_SWITCH_SEARCHED_ITEM_CLICKED
97+
}
98+
if (selectedOption.isRecentlyVisited) {
99+
return appSelectorGAEvents.DA_SWITCH_RECENTLY_VISITED_CLICKED
100+
}
101+
return appSelectorGAEvents.DA_SWITCH_SEARCHED_APP_CLICKED
102+
}

src/components/AppSelector/ChartSelector.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ import {
2121
SelectPickerOptionType,
2222
ContextSwitcher,
2323
Icon,
24+
handleAnalyticsEvent,
2425
} from '@devtron-labs/devtron-fe-common-lib'
2526
import { mapByKey } from '../common'
2627
import { ChartSelectorType } from './AppSelector.types'
28+
import { appSelectorGAEvents } from './constants'
2729

2830
export default function ChartSelector({
2931
primaryKey,
@@ -46,6 +48,10 @@ export default function ChartSelector({
4648
onChange(selected)
4749
return
4850
}
51+
handleAnalyticsEvent({
52+
category: 'Chart Store',
53+
action: appSelectorGAEvents.CS_CHART_DETAIL_SWITCH_ITEM_CLICKED,
54+
})
4955
const keys = listMap.get(selected.value)
5056
const replacements = [...matchedKeys].reduce((agg, curr) => ({ ...agg, [curr]: keys[curr] }), {})
5157
const newUrl = generatePath(path, { ...replacements, [primaryKey]: selected.value })

src/components/AppSelector/constants.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ export const getMinCharSearchPlaceholderGroup = (resourceKind): RecentlyVisitedG
55
options: [{ value: 0, label: 'Type 3 characters to search', isDisabled: true }],
66
})
77

8-
export const APP_DETAILS_GA_EVENTS = {
9-
RecentlyVisitedApps: {
10-
category: 'App Selector',
11-
action: 'DA_SWITCH_RECENTLY_VISITED_CLICKED',
12-
},
13-
SearchesAppClicked: {
14-
category: 'App Selector',
15-
action: 'DA_SWITCH_SEARCHED_APP_CLICKED',
16-
},
8+
export const appSelectorGAEvents = {
9+
DA_SWITCH_RECENTLY_VISITED_CLICKED: 'DA_SWITCH_RECENTLY_VISITED_CLICKED',
10+
DA_SWITCH_SEARCHED_APP_CLICKED: 'DA_SWITCH_SEARCHED_APP_CLICKED',
11+
JOB_SWITCH_RECENTLY_VISITED_CLICKED: 'JOB_SWITCH_RECENTLY_VISITED_CLICKED',
12+
JOB_SWITCH_SEARCHED_ITEM_CLICKED: 'JOB_SWITCH_SEARCHED_ITEM_CLICKED',
13+
CS_CHART_DETAIL_SWITCH_ITEM_CLICKED: 'CS_CHART_DETAIL_SWITCH_ITEM_CLICKED',
1714
}

src/components/ApplicationGroup/Constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ export const ENV_APP_GROUP_GA_EVENTS = {
173173
category: 'Configuration',
174174
action: 'Configuration Clicked',
175175
},
176+
EnvironmentHeaderRecentlyVisitedClicked: {
177+
category: 'Environment',
178+
action: 'AG_SWITCH_RECENTLY_VISITED_CLICKED',
179+
},
180+
EnvironmentHeaderSearchedItemClicked: {
181+
category: 'Environment',
182+
action: 'AG_SWITCH_SEARCHED_ITEM_CLICKED',
183+
},
176184
}
177185

178186
export const GROUP_LIST_HEADER = {

src/components/ApplicationGroup/EnvSelector.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,19 @@
1515
*/
1616

1717
import { useRef, useState } from 'react'
18-
import ReactGA from 'react-ga4'
1918

2019
import {
2120
ContextSwitcher,
21+
handleAnalyticsEvent,
2222
RecentlyVisitedOptions,
2323
SelectPickerProps,
2424
useAsync,
2525
useUserPreferences,
2626
} from '@devtron-labs/devtron-fe-common-lib'
2727

28-
import { APP_DETAILS_GA_EVENTS } from '@Components/AppSelector/constants'
29-
3028
import { EnvSelectorType } from './AppGroup.types'
3129
import { envListOptions } from './AppGroup.utils'
30+
import { ENV_APP_GROUP_GA_EVENTS } from './Constants'
3231

3332
export const EnvSelector = ({ onChange, envId, envName }: EnvSelectorType) => {
3433
const abortControllerRef = useRef<AbortController>(new AbortController())
@@ -60,11 +59,12 @@ export const EnvSelector = ({ onChange, envId, envName }: EnvSelectorType) => {
6059

6160
onChange(selectedOption)
6261

63-
ReactGA.event(
64-
selectedOption.isRecentlyVisited
65-
? APP_DETAILS_GA_EVENTS.RecentlyVisitedApps
66-
: APP_DETAILS_GA_EVENTS.SearchesAppClicked,
67-
)
62+
handleAnalyticsEvent({
63+
category: 'Environment',
64+
action: selectedOption.isRecentlyVisited
65+
? ENV_APP_GROUP_GA_EVENTS.EnvironmentHeaderRecentlyVisitedClicked.action
66+
: ENV_APP_GROUP_GA_EVENTS.EnvironmentHeaderSearchedItemClicked.action,
67+
})
6868
}
6969

7070
return (

src/components/ResourceBrowser/Constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,8 @@ export const AI_BUTTON_CONFIG_MAP: Record<string, ShowAIButtonConfig> = Object.f
392392
excludeValues: new Set(['Approved,Issued']),
393393
},
394394
})
395+
396+
export const ResourceBrowserGAEvent = {
397+
RB_SWITCH_CLUSTER_RECENTLY_VISITED_CLICKED: 'RB_SWITCH_CLUSTER_RECENTLY_VISITED_CLICKED',
398+
RB_SWITCH_CLUSTER_SEARCHED_ITEM_CLICKED: 'RB_SWITCH_CLUSTER_SEARCHED_ITEM_CLICKED',
399+
}

src/components/ResourceBrowser/ResourceList/ClusterSelector.tsx

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@ import {
2121
Badge,
2222
ComponentSizeType,
2323
ContextSwitcher,
24+
handleAnalyticsEvent,
2425
Icon,
2526
PopupMenu,
27+
RecentlyVisitedOptions,
28+
ResourceKindType,
2629
SelectPickerProps,
30+
useUserPreferences,
2731
} from '@devtron-labs/devtron-fe-common-lib'
2832

2933
import { ReactComponent as MenuDots } from '@Icons/ic-more-vertical.svg'
3034
import { DEFAULT_CLUSTER_ID } from '@Pages/GlobalConfigurations/ClustersAndEnvironments'
3135
import DeleteClusterConfirmationModal from '@Pages/GlobalConfigurations/ClustersAndEnvironments/DeleteClusterConfirmationModal'
3236

3337
import { URLS } from '../../../config'
38+
import { ResourceBrowserGAEvent } from '../Constants'
3439
import { ClusterSelectorType } from '../Types'
3540
import { getClusterSelectOptions } from './utils'
3641

@@ -50,6 +55,33 @@ const ClusterSelector: React.FC<ClusterSelectorType> = ({
5055
const defaultOption = filteredClusterList.find((item) =>
5156
isInstallationStatusView ? String(item.installationId) === clusterId : String(item.value) === clusterId,
5257
)
58+
const clusterName = defaultOption?.label
59+
60+
const handleOnChange = (selected: RecentlyVisitedOptions) => {
61+
if (selected.value === Number(defaultOption?.value)) {
62+
return
63+
}
64+
65+
handleAnalyticsEvent({
66+
category: 'Resource Browser',
67+
action: selected.isRecentlyVisited
68+
? ResourceBrowserGAEvent.RB_SWITCH_CLUSTER_RECENTLY_VISITED_CLICKED
69+
: ResourceBrowserGAEvent.RB_SWITCH_CLUSTER_SEARCHED_ITEM_CLICKED,
70+
})
71+
72+
onChange(selected)
73+
}
74+
75+
const isAppDataAvailable = !!clusterId
76+
77+
const { recentlyVisitedResources } = useUserPreferences({
78+
recentlyVisitedFetchConfig: {
79+
id: +clusterId,
80+
name: clusterName,
81+
resourceKind: ResourceKindType.cluster,
82+
isDataAvailable: isAppDataAvailable,
83+
},
84+
})
5385

5486
const [inputValue, setInputValue] = useState('')
5587

@@ -76,9 +108,13 @@ const ClusterSelector: React.FC<ClusterSelectorType> = ({
76108
<ContextSwitcher
77109
inputId={`cluster-switcher-${clusterId}`}
78110
isLoading={isClusterListLoading}
79-
onChange={onChange}
111+
onChange={handleOnChange}
80112
value={defaultOption}
81-
options={getClusterSelectOptions(filteredClusterList, isInstallationStatusView)}
113+
options={getClusterSelectOptions(
114+
filteredClusterList,
115+
recentlyVisitedResources,
116+
isInstallationStatusView,
117+
)}
82118
inputValue={inputValue}
83119
onInputChange={onInputChange}
84120
/>

src/components/ResourceBrowser/ResourceList/utils.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import {
18+
BaseRecentlyVisitedEntitiesTypes,
1819
ClusterDetail,
1920
DocLink,
2021
DocLinkProps,
@@ -165,12 +166,29 @@ export const getOptionsValue = (option: ClusterOptionType, isInstallationStatusV
165166
// clusterId as this installationId
166167
isInstallationStatusView ? `installation-${String(option.installationId)}` : option.value
167168

168-
export const getClusterSelectOptions = (clusterList, isInstallationStatusView): RecentlyVisitedGroupedOptionsType[] => [
169-
{
170-
label: 'All Clusters',
171-
options: clusterList?.map((option) => ({
172-
...option,
173-
value: +getOptionsValue(option, isInstallationStatusView),
174-
})) as RecentlyVisitedOptions[],
175-
},
176-
]
169+
const getAllCluster = ({ clusterList, isInstallationStatusView }) => ({
170+
label: 'All Clusters',
171+
options: clusterList?.map((option) => ({
172+
...option,
173+
value: +getOptionsValue(option, isInstallationStatusView),
174+
})) as RecentlyVisitedOptions[],
175+
})
176+
177+
export const getClusterSelectOptions = (
178+
clusterList,
179+
recentlyVisitedResources,
180+
isInstallationStatusView,
181+
): RecentlyVisitedGroupedOptionsType[] =>
182+
recentlyVisitedResources?.length
183+
? [
184+
{
185+
label: 'Recently Visited',
186+
options: recentlyVisitedResources.map((cluster: BaseRecentlyVisitedEntitiesTypes) => ({
187+
label: cluster.name,
188+
value: cluster.id,
189+
isRecentlyVisited: true,
190+
})) as RecentlyVisitedOptions[],
191+
},
192+
getAllCluster({ clusterList, isInstallationStatusView }),
193+
]
194+
: [getAllCluster({ clusterList, isInstallationStatusView })]

0 commit comments

Comments
 (0)