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(