mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
feat: add plausible tracking to scheduling (#5668)
Adds plausible tracking with actions: - scheduled-created - scheduled-updated - scheduled-rejected - scheduled-applied Closes # [1-1630](https://linear.app/unleash/issue/1-1630/add-plausible-metrics) --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
fd34f35e0e
commit
75bdd73c15
@ -31,6 +31,7 @@ import {
|
|||||||
ChangeRequestRejectScheduledDialogue,
|
ChangeRequestRejectScheduledDialogue,
|
||||||
} from './ChangeRequestScheduledDialogs/changeRequestScheduledDialogs';
|
} from './ChangeRequestScheduledDialogs/changeRequestScheduledDialogs';
|
||||||
import { ScheduleChangeRequestDialog } from './ChangeRequestScheduledDialogs/ScheduleChangeRequestDialog';
|
import { ScheduleChangeRequestDialog } from './ChangeRequestScheduledDialogs/ScheduleChangeRequestDialog';
|
||||||
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
|
|
||||||
const StyledAsideBox = styled(Box)(({ theme }) => ({
|
const StyledAsideBox = styled(Box)(({ theme }) => ({
|
||||||
width: '30%',
|
width: '30%',
|
||||||
@ -100,6 +101,7 @@ export const ChangeRequestOverview: FC = () => {
|
|||||||
const { isChangeRequestConfiguredForReview } =
|
const { isChangeRequestConfiguredForReview } =
|
||||||
useChangeRequestsEnabled(projectId);
|
useChangeRequestsEnabled(projectId);
|
||||||
const scheduleChangeRequests = useUiFlag('scheduledConfigurationChanges');
|
const scheduleChangeRequests = useUiFlag('scheduledConfigurationChanges');
|
||||||
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
|
||||||
if (!changeRequest) {
|
if (!changeRequest) {
|
||||||
return null;
|
return null;
|
||||||
@ -109,6 +111,8 @@ export const ChangeRequestOverview: FC = () => {
|
|||||||
changeRequest.environment,
|
changeRequest.environment,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const hasSchedule = Boolean(changeRequest.schedule?.scheduledAt);
|
||||||
|
|
||||||
const onApplyChanges = async () => {
|
const onApplyChanges = async () => {
|
||||||
try {
|
try {
|
||||||
await changeState(projectId, Number(id), {
|
await changeState(projectId, Number(id), {
|
||||||
@ -122,12 +126,22 @@ export const ChangeRequestOverview: FC = () => {
|
|||||||
title: 'Success',
|
title: 'Success',
|
||||||
text: 'Changes applied',
|
text: 'Changes applied',
|
||||||
});
|
});
|
||||||
|
if (hasSchedule) {
|
||||||
|
trackEvent('scheduled-configuration-changes', {
|
||||||
|
props: {
|
||||||
|
action: 'scheduled-applied',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onScheduleChangeRequest = async (scheduledDate: Date) => {
|
const onScheduleChangeRequest = async (scheduledDate: Date) => {
|
||||||
|
const plausibleAction = hasSchedule
|
||||||
|
? 'scheduled-updated'
|
||||||
|
: 'scheduled-created';
|
||||||
try {
|
try {
|
||||||
await changeState(projectId, Number(id), {
|
await changeState(projectId, Number(id), {
|
||||||
state: 'Scheduled',
|
state: 'Scheduled',
|
||||||
@ -141,6 +155,11 @@ export const ChangeRequestOverview: FC = () => {
|
|||||||
title: 'Success',
|
title: 'Success',
|
||||||
text: 'Changes scheduled',
|
text: 'Changes scheduled',
|
||||||
});
|
});
|
||||||
|
trackEvent('scheduled-configuration-changes', {
|
||||||
|
props: {
|
||||||
|
action: plausibleAction,
|
||||||
|
},
|
||||||
|
});
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
}
|
}
|
||||||
@ -193,6 +212,13 @@ export const ChangeRequestOverview: FC = () => {
|
|||||||
});
|
});
|
||||||
refetchChangeRequest();
|
refetchChangeRequest();
|
||||||
refetchChangeRequestOpen();
|
refetchChangeRequestOpen();
|
||||||
|
if (hasSchedule) {
|
||||||
|
trackEvent('scheduled-configuration-changes', {
|
||||||
|
props: {
|
||||||
|
action: 'scheduled-rejected',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
setToastApiError(formatUnknownError(error));
|
setToastApiError(formatUnknownError(error));
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,8 @@ export type CustomEvents =
|
|||||||
| 'project-mode'
|
| 'project-mode'
|
||||||
| 'dependent_features'
|
| 'dependent_features'
|
||||||
| 'playground_token_input_used'
|
| 'playground_token_input_used'
|
||||||
| 'search-filter';
|
| 'search-filter'
|
||||||
|
| 'scheduled-configuration-changes';
|
||||||
|
|
||||||
export const usePlausibleTracker = () => {
|
export const usePlausibleTracker = () => {
|
||||||
const plausible = useContext(PlausibleContext);
|
const plausible = useContext(PlausibleContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user