mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-09 01:17:06 +02: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:
parent
6dbea08d0b
commit
ab4c1e0193
@ -1,4 +1,4 @@
|
|||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { trim } from 'component/common/util';
|
import { trim } from 'component/common/util';
|
||||||
import { StickinessSelect } from 'component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect';
|
import { StickinessSelect } from 'component/feature/StrategyTypes/FlexibleStrategy/StickinessSelect/StickinessSelect';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
@ -10,6 +10,7 @@ import Input from 'component/common/Input/Input';
|
|||||||
import { FeatureTogglesLimitTooltip } from './FeatureTogglesLimitTooltip';
|
import { FeatureTogglesLimitTooltip } from './FeatureTogglesLimitTooltip';
|
||||||
import { FeatureFlagNamingTooltip } from './FeatureFlagNamingTooltip';
|
import { FeatureFlagNamingTooltip } from './FeatureFlagNamingTooltip';
|
||||||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
interface IProjectForm {
|
interface IProjectForm {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@ -127,6 +128,27 @@ export const validateFeatureNamingExample = ({
|
|||||||
return { state: 'valid' };
|
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> = ({
|
const ProjectForm: React.FC<IProjectForm> = ({
|
||||||
children,
|
children,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -157,6 +179,13 @@ const ProjectForm: React.FC<IProjectForm> = ({
|
|||||||
const { uiConfig } = useUiConfig();
|
const { uiConfig } = useUiConfig();
|
||||||
const shouldShowFlagNaming = uiConfig.flags.featureNamingPattern;
|
const shouldShowFlagNaming = uiConfig.flags.featureNamingPattern;
|
||||||
|
|
||||||
|
const { setPreviousPattern, trackPattern } =
|
||||||
|
useFeatureNamePatternTracking();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setPreviousPattern(featureNamingPattern || '');
|
||||||
|
}, [projectId]);
|
||||||
|
|
||||||
const updateNamingExampleError = ({
|
const updateNamingExampleError = ({
|
||||||
example,
|
example,
|
||||||
pattern,
|
pattern,
|
||||||
@ -208,7 +237,12 @@ const ProjectForm: React.FC<IProjectForm> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledForm onSubmit={handleSubmit}>
|
<StyledForm
|
||||||
|
onSubmit={submitEvent => {
|
||||||
|
handleSubmit(submitEvent);
|
||||||
|
trackPattern(featureNamingPattern);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<StyledDescription>What is your project Id?</StyledDescription>
|
<StyledDescription>What is your project Id?</StyledDescription>
|
||||||
<StyledInput
|
<StyledInput
|
||||||
label="Project Id"
|
label="Project Id"
|
||||||
|
@ -46,7 +46,8 @@ export type CustomEvents =
|
|||||||
| 'strategy-variants'
|
| 'strategy-variants'
|
||||||
| 'search-filter-suggestions'
|
| 'search-filter-suggestions'
|
||||||
| 'project-metrics'
|
| 'project-metrics'
|
||||||
| 'open-integration';
|
| 'open-integration'
|
||||||
|
| 'feature-naming-pattern';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user