From a1952aca9ddd872c59972a35d1815d8b8b4cecaa Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 22 Mar 2023 20:04:02 +0200 Subject: [PATCH] Feat: plausible tracking stickiness (#3363) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds plausible tracking when default project stickiness is changed ## About the changes Closes # ### Important files ## Discussion points --------- Signed-off-by: andreas-unleash --- .../project/Project/CreateProject/CreateProject.tsx | 10 +++++++++- .../project/Project/EditProject/EditProject.tsx | 9 ++++++++- .../component/project/Project/hooks/useProjectForm.ts | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/src/component/project/Project/CreateProject/CreateProject.tsx b/frontend/src/component/project/Project/CreateProject/CreateProject.tsx index f2564ed93a..af8f2d92fb 100644 --- a/frontend/src/component/project/Project/CreateProject/CreateProject.tsx +++ b/frontend/src/component/project/Project/CreateProject/CreateProject.tsx @@ -1,6 +1,8 @@ import { useNavigate } from 'react-router-dom'; 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 FormTemplate from 'component/common/FormTemplate/FormTemplate'; 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 { formatUnknownError } from 'utils/formatUnknownError'; import { GO_BACK } from 'constants/navigate'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const CREATE_PROJECT_BTN = 'CREATE_PROJECT_BTN'; @@ -18,6 +21,7 @@ const CreateProject = () => { const { refetchUser } = useAuthUser(); const { uiConfig } = useUiConfig(); const navigate = useNavigate(); + const { trackEvent } = usePlausibleTracker(); const { projectId, projectName, @@ -56,6 +60,10 @@ const CreateProject = () => { confetti: true, type: 'success', }); + + if (projectStickiness !== DEFAULT_PROJECT_STICKINESS) { + trackEvent('project_stickiness_set'); + } } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } diff --git a/frontend/src/component/project/Project/EditProject/EditProject.tsx b/frontend/src/component/project/Project/EditProject/EditProject.tsx index 9276b33e54..6540eb27c8 100644 --- a/frontend/src/component/project/Project/EditProject/EditProject.tsx +++ b/frontend/src/component/project/Project/EditProject/EditProject.tsx @@ -1,6 +1,8 @@ import { useNavigate } from 'react-router-dom'; 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 FormTemplate from 'component/common/FormTemplate/FormTemplate'; import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions'; @@ -15,6 +17,7 @@ import AccessContext from 'contexts/AccessContext'; import { Alert } from '@mui/material'; import { GO_BACK } from 'constants/navigate'; import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; const EDIT_PROJECT_BTN = 'EDIT_PROJECT_BTN'; @@ -26,6 +29,7 @@ const EditProject = () => { const { project } = useProject(id); const { defaultStickiness } = useDefaultProjectSettings(id); const navigate = useNavigate(); + const { trackEvent } = usePlausibleTracker(); const { projectId, @@ -78,6 +82,9 @@ const EditProject = () => { title: 'Project information updated', type: 'success', }); + if (projectStickiness !== DEFAULT_PROJECT_STICKINESS) { + trackEvent('project_stickiness_set'); + } } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } diff --git a/frontend/src/component/project/Project/hooks/useProjectForm.ts b/frontend/src/component/project/Project/hooks/useProjectForm.ts index d161602562..7e34bb45d4 100644 --- a/frontend/src/component/project/Project/hooks/useProjectForm.ts +++ b/frontend/src/component/project/Project/hooks/useProjectForm.ts @@ -5,12 +5,12 @@ import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings'; export type ProjectMode = 'open' | 'protected'; export type DefaultStickiness = 'default' | 'userId' | 'sessionId' | 'random'; - +export const DEFAULT_PROJECT_STICKINESS = 'default'; const useProjectForm = ( initialProjectId = '', initialProjectName = '', initialProjectDesc = '', - initialProjectStickiness: DefaultStickiness = 'default', + initialProjectStickiness: DefaultStickiness = DEFAULT_PROJECT_STICKINESS, initialProjectMode: ProjectMode = 'open' ) => { const [projectId, setProjectId] = useState(initialProjectId);