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

Feat: plausible tracking stickiness (#3363)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

Adds plausible tracking when default project stickiness is changed

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-03-22 20:04:02 +02:00 committed by GitHub
parent 0d1d3a2762
commit a1952aca9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -1,6 +1,8 @@
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import ProjectForm from '../ProjectForm/ProjectForm'; import ProjectForm from '../ProjectForm/ProjectForm';
import useProjectForm from '../hooks/useProjectForm'; import useProjectForm, {
DEFAULT_PROJECT_STICKINESS,
} from '../hooks/useProjectForm';
import { CreateButton } from 'component/common/CreateButton/CreateButton'; import { CreateButton } from 'component/common/CreateButton/CreateButton';
import FormTemplate from 'component/common/FormTemplate/FormTemplate'; import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import { CREATE_PROJECT } from 'component/providers/AccessProvider/permissions'; import { CREATE_PROJECT } from 'component/providers/AccessProvider/permissions';
@ -10,6 +12,7 @@ import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import useToast from 'hooks/useToast'; import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError'; import { formatUnknownError } from 'utils/formatUnknownError';
import { GO_BACK } from 'constants/navigate'; import { GO_BACK } from 'constants/navigate';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const CREATE_PROJECT_BTN = 'CREATE_PROJECT_BTN'; const CREATE_PROJECT_BTN = 'CREATE_PROJECT_BTN';
@ -18,6 +21,7 @@ const CreateProject = () => {
const { refetchUser } = useAuthUser(); const { refetchUser } = useAuthUser();
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
const navigate = useNavigate(); const navigate = useNavigate();
const { trackEvent } = usePlausibleTracker();
const { const {
projectId, projectId,
projectName, projectName,
@ -56,6 +60,10 @@ const CreateProject = () => {
confetti: true, confetti: true,
type: 'success', type: 'success',
}); });
if (projectStickiness !== DEFAULT_PROJECT_STICKINESS) {
trackEvent('project_stickiness_set');
}
} catch (error: unknown) { } catch (error: unknown) {
setToastApiError(formatUnknownError(error)); setToastApiError(formatUnknownError(error));
} }

View File

@ -1,6 +1,8 @@
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import ProjectForm from '../ProjectForm/ProjectForm'; import ProjectForm from '../ProjectForm/ProjectForm';
import useProjectForm from '../hooks/useProjectForm'; import useProjectForm, {
DEFAULT_PROJECT_STICKINESS,
} from '../hooks/useProjectForm';
import { UpdateButton } from 'component/common/UpdateButton/UpdateButton'; import { UpdateButton } from 'component/common/UpdateButton/UpdateButton';
import FormTemplate from 'component/common/FormTemplate/FormTemplate'; import FormTemplate from 'component/common/FormTemplate/FormTemplate';
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions'; import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions';
@ -15,6 +17,7 @@ import AccessContext from 'contexts/AccessContext';
import { Alert } from '@mui/material'; import { Alert } from '@mui/material';
import { GO_BACK } from 'constants/navigate'; import { GO_BACK } from 'constants/navigate';
import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings'; import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const EDIT_PROJECT_BTN = 'EDIT_PROJECT_BTN'; const EDIT_PROJECT_BTN = 'EDIT_PROJECT_BTN';
@ -26,6 +29,7 @@ const EditProject = () => {
const { project } = useProject(id); const { project } = useProject(id);
const { defaultStickiness } = useDefaultProjectSettings(id); const { defaultStickiness } = useDefaultProjectSettings(id);
const navigate = useNavigate(); const navigate = useNavigate();
const { trackEvent } = usePlausibleTracker();
const { const {
projectId, projectId,
@ -78,6 +82,9 @@ const EditProject = () => {
title: 'Project information updated', title: 'Project information updated',
type: 'success', type: 'success',
}); });
if (projectStickiness !== DEFAULT_PROJECT_STICKINESS) {
trackEvent('project_stickiness_set');
}
} catch (error: unknown) { } catch (error: unknown) {
setToastApiError(formatUnknownError(error)); setToastApiError(formatUnknownError(error));
} }

View File

@ -5,12 +5,12 @@ import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings';
export type ProjectMode = 'open' | 'protected'; export type ProjectMode = 'open' | 'protected';
export type DefaultStickiness = 'default' | 'userId' | 'sessionId' | 'random'; export type DefaultStickiness = 'default' | 'userId' | 'sessionId' | 'random';
export const DEFAULT_PROJECT_STICKINESS = 'default';
const useProjectForm = ( const useProjectForm = (
initialProjectId = '', initialProjectId = '',
initialProjectName = '', initialProjectName = '',
initialProjectDesc = '', initialProjectDesc = '',
initialProjectStickiness: DefaultStickiness = 'default', initialProjectStickiness: DefaultStickiness = DEFAULT_PROJECT_STICKINESS,
initialProjectMode: ProjectMode = 'open' initialProjectMode: ProjectMode = 'open'
) => { ) => {
const [projectId, setProjectId] = useState(initialProjectId); const [projectId, setProjectId] = useState(initialProjectId);