From 7c8647f9f37289df9daac46a8ca94075a857e1e6 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 11 Jan 2023 11:24:11 +0200 Subject: [PATCH] fix track invite-link user created event (#2689) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: andreas-unleash Adds plausible tracking of invite-link use for all auth types. ## About the changes Closes # ### Important files ## Discussion points Signed-off-by: andreas-unleash --- .../user/Authentication/Authentication.tsx | 19 ++++++++++++++++++- frontend/src/component/user/Login/Login.tsx | 2 +- .../src/component/user/NewUser/NewUser.tsx | 7 ------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/frontend/src/component/user/Authentication/Authentication.tsx b/frontend/src/component/user/Authentication/Authentication.tsx index 45b2583c49..a9edb2ed3a 100644 --- a/frontend/src/component/user/Authentication/Authentication.tsx +++ b/frontend/src/component/user/Authentication/Authentication.tsx @@ -15,15 +15,32 @@ import { ConditionallyRender } from 'component/common/ConditionallyRender/Condit import { Alert } from '@mui/material'; import { useAuthDetails } from 'hooks/api/getters/useAuth/useAuthDetails'; import { AUTH_PAGE_ID } from 'utils/testIds'; +import { useEffect } from 'react'; +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; interface IAuthenticationProps { redirect: string; + invited?: boolean; } -const Authentication = ({ redirect }: IAuthenticationProps) => { +const Authentication = ({ + redirect, + invited = false, +}: IAuthenticationProps) => { const { authDetails } = useAuthDetails(); const params = useQueryParams(); const error = params.get('errorMsg'); + const { trackEvent } = usePlausibleTracker(); + + useEffect(() => { + if (invited) { + trackEvent('invite', { + props: { + eventType: 'user created', + }, + }); + } + }, [invited, trackEvent]); if (!authDetails) { return null; diff --git a/frontend/src/component/user/Login/Login.tsx b/frontend/src/component/user/Login/Login.tsx index 7e9d1adce0..dca420fad4 100644 --- a/frontend/src/component/user/Login/Login.tsx +++ b/frontend/src/component/user/Login/Login.tsx @@ -61,7 +61,7 @@ const Login = () => { } /> - + ); diff --git a/frontend/src/component/user/NewUser/NewUser.tsx b/frontend/src/component/user/NewUser/NewUser.tsx index f38bf0255d..0ccb0516d5 100644 --- a/frontend/src/component/user/NewUser/NewUser.tsx +++ b/frontend/src/component/user/NewUser/NewUser.tsx @@ -3,7 +3,6 @@ import { useNavigate } from 'react-router-dom'; import { Box, TextField, Typography } from '@mui/material'; import { CREATED, OK } from 'constants/statusCodes'; import useToast from 'hooks/useToast'; -import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; import useResetPassword from 'hooks/api/getters/useResetPassword/useResetPassword'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { useUserInvite } from 'hooks/api/getters/useUserInvite/useUserInvite'; @@ -40,17 +39,11 @@ export const NewUser = () => { const { resetPassword, loading: isPasswordSubmitting } = useAuthResetPasswordApi(); const passwordDisabled = authDetails?.defaultHidden === true; - const { trackEvent } = usePlausibleTracker(); const onSubmitInvitedUser = async (password: string) => { try { const res = await addUser(secret, { name, email, password }); if (res.status === CREATED) { - trackEvent('invite', { - props: { - eventType: 'user created', - }, - }); navigate('/login?invited=true'); } else { setToastApiError(