1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: tracking feature buttons clicks (#5714)

This commit is contained in:
Jaanus Sellin 2023-12-21 11:01:16 +02:00 committed by GitHub
parent 9b7981047d
commit 3926ec6c51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 deletions

View File

@ -14,7 +14,7 @@ test('all options are drawn', async () => {
render(<FeatureToggleListActions onExportClick={() => {}} />); render(<FeatureToggleListActions onExportClick={() => {}} />);
const batchReviveButton = await screen.findByTitle('Group actions'); const batchReviveButton = await screen.findByTitle('Options');
await userEvent.click(batchReviveButton!); await userEvent.click(batchReviveButton!);

View File

@ -17,6 +17,7 @@ import { useUiFlag } from 'hooks/useUiFlag';
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions'; import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions';
import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC'; import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC';
import { useCreateFeaturePath } from 'component/feature/CreateFeatureButton/useCreateFeaturePath'; import { useCreateFeaturePath } from 'component/feature/CreateFeatureButton/useCreateFeaturePath';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const StyledActions = styled('div')(({ theme }) => ({ const StyledActions = styled('div')(({ theme }) => ({
display: 'flex', display: 'flex',
@ -35,6 +36,7 @@ interface IFeatureToggleListActions {
export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({ export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({
onExportClick, onExportClick,
}: IFeatureToggleListActions) => { }: IFeatureToggleListActions) => {
const { trackEvent } = usePlausibleTracker();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const featuresExportImport = useUiFlag('featuresExportImport'); const featuresExportImport = useUiFlag('featuresExportImport');
const createFeature = useCreateFeaturePath({ const createFeature = useCreateFeaturePath({
@ -45,6 +47,11 @@ export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({
const open = Boolean(anchorEl); const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget); setAnchorEl(event.currentTarget);
trackEvent('search-feature-buttons', {
props: {
action: 'options',
},
});
}; };
const handleClose = () => { const handleClose = () => {
setAnchorEl(null); setAnchorEl(null);
@ -60,7 +67,7 @@ export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({
e.stopPropagation(); e.stopPropagation();
}} }}
> >
<Tooltip title='Group actions' arrow describeChild> <Tooltip title='Options' arrow describeChild>
<IconButton <IconButton
id={id} id={id}
aria-controls={open ? menuId : undefined} aria-controls={open ? menuId : undefined}
@ -91,10 +98,17 @@ export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({
<PermissionHOC permission={CREATE_FEATURE}> <PermissionHOC permission={CREATE_FEATURE}>
{({ hasAccess }) => ( {({ hasAccess }) => (
<MenuItem <MenuItem
onClick={handleClose}
component={Link} component={Link}
disabled={!hasAccess} disabled={!hasAccess}
to={createFeature!.path} to={createFeature!.path}
onClick={() => {
handleClose();
trackEvent('search-feature-buttons', {
props: {
action: 'new-feature',
},
});
}}
> >
<ListItemIcon> <ListItemIcon>
<Add /> <Add />
@ -114,6 +128,11 @@ export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({
onClick={() => { onClick={() => {
onExportClick(); onExportClick();
handleClose(); handleClose();
trackEvent('search-feature-buttons', {
props: {
action: 'export',
},
});
}} }}
> >
<ListItemIcon> <ListItemIcon>

View File

@ -46,6 +46,7 @@ import { useUiFlag } from 'hooks/useUiFlag';
import { FeatureToggleListTable as LegacyFeatureToggleListTable } from './LegacyFeatureToggleListTable'; import { FeatureToggleListTable as LegacyFeatureToggleListTable } from './LegacyFeatureToggleListTable';
import { FeatureToggleListActions } from './FeatureToggleListActions/FeatureToggleListActions'; import { FeatureToggleListActions } from './FeatureToggleListActions/FeatureToggleListActions';
import useLoading from 'hooks/useLoading'; import useLoading from 'hooks/useLoading';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
export const featuresPlaceholder = Array(15).fill({ export const featuresPlaceholder = Array(15).fill({
name: 'Name of the feature', name: 'Name of the feature',
@ -59,6 +60,7 @@ const columnHelper = createColumnHelper<FeatureSearchResponseSchema>();
const FeatureToggleListTableComponent: VFC = () => { const FeatureToggleListTableComponent: VFC = () => {
const theme = useTheme(); const theme = useTheme();
const { trackEvent } = usePlausibleTracker();
const { environments } = useEnvironments(); const { environments } = useEnvironments();
const enabledEnvironments = environments const enabledEnvironments = environments
.filter((env) => env.enabled) .filter((env) => env.enabled)
@ -285,6 +287,13 @@ const FeatureToggleListTableComponent: VFC = () => {
to='/archive' to='/archive'
underline='always' underline='always'
sx={{ marginRight: 2, ...focusable(theme) }} sx={{ marginRight: 2, ...focusable(theme) }}
onClick={() => {
trackEvent('search-feature-buttons', {
props: {
action: 'archive',
},
});
}}
> >
View archive View archive
</Link> </Link>

View File

@ -52,7 +52,8 @@ export type CustomEvents =
| 'dependent_features' | 'dependent_features'
| 'playground_token_input_used' | 'playground_token_input_used'
| 'search-filter' | 'search-filter'
| 'scheduled-configuration-changes'; | 'scheduled-configuration-changes'
| 'search-feature-buttons';
export const usePlausibleTracker = () => { export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext); const plausible = useContext(PlausibleContext);