1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

feat: add feature naming pattern tracking (#4678)

This PR adds plausible metrics for feature naming patterns. The changes
are tracked whenever the form is submitted and the naming pattern has
changed. We track three different actions:
- added :: if there was no pattern before and now there is one
- removed :: if there was a pattern before and now there is none
- changed :: if there was a pattern before and now there is a different
one

The corresponding event type has been created in plausible.
This commit is contained in:
Thomas Heartman 2023-09-14 09:32:15 +02:00 committed by GitHub
parent 6dbea08d0b
commit ab4c1e0193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { trim } from 'component/common/util';
import { StickinessSelect } from 'component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
@ -10,6 +10,7 @@ import Input from 'component/common/Input/Input';
import { FeatureTogglesLimitTooltip } from './FeatureTogglesLimitTooltip';
import { FeatureFlagNamingTooltip } from './FeatureFlagNamingTooltip';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IProjectForm {
projectId: string;
@ -127,6 +128,27 @@ export const validateFeatureNamingExample = ({
return { state: 'valid' };
};
const useFeatureNamePatternTracking = () => {
const [previousPattern, setPreviousPattern] = React.useState<string>('');
const { trackEvent } = usePlausibleTracker();
const eventName = 'feature-naming-pattern' as const;
const trackPattern = (pattern: string = '') => {
if (pattern === previousPattern) {
// do nothing; they've probably updated something else in the
// project.
} else if (pattern === '' && previousPattern !== '') {
trackEvent(eventName, { props: { action: 'removed' } });
} else if (pattern !== '' && previousPattern === '') {
trackEvent(eventName, { props: { action: 'added' } });
} else if (pattern !== '' && previousPattern !== '') {
trackEvent(eventName, { props: { action: 'edited' } });
}
};
return { trackPattern, setPreviousPattern };
};
const ProjectForm: React.FC<IProjectForm> = ({
children,
handleSubmit,
@ -157,6 +179,13 @@ const ProjectForm: React.FC<IProjectForm> = ({
const { uiConfig } = useUiConfig();
const shouldShowFlagNaming = uiConfig.flags.featureNamingPattern;
const { setPreviousPattern, trackPattern } =
useFeatureNamePatternTracking();
useEffect(() => {
setPreviousPattern(featureNamingPattern || '');
}, [projectId]);
const updateNamingExampleError = ({
example,
pattern,
@ -208,7 +237,12 @@ const ProjectForm: React.FC<IProjectForm> = ({
};
return (
<StyledForm onSubmit={handleSubmit}>
<StyledForm
onSubmit={submitEvent => {
handleSubmit(submitEvent);
trackPattern(featureNamingPattern);
}}
>
<StyledDescription>What is your project Id?</StyledDescription>
<StyledInput
label="Project Id"

View File

@ -46,7 +46,8 @@ export type CustomEvents =
| 'strategy-variants'
| 'search-filter-suggestions'
| 'project-metrics'
| 'open-integration';
| 'open-integration'
| 'feature-naming-pattern';
export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);