chore: telemetry update & refactoring

This commit is contained in:
LAKHAN BAHETI 2024-03-12 22:07:23 +05:30
parent 5b2e271f7c
commit e551dacb7e
6 changed files with 44 additions and 39 deletions

View File

@ -25,7 +25,7 @@ import { EUserWorkspaceRoles, ROLE } from "constants/workspace";
// helpers
import { getUserRole } from "helpers/user.helper";
// hooks
import { useEventTracker } from "hooks/store";
import { useApplication, useEventTracker } from "hooks/store";
import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown";
// assets
import userDark from "public/onboarding/user-dark.svg";
@ -271,6 +271,9 @@ export const InviteMembers: React.FC<Props> = (props) => {
const { resolvedTheme } = useTheme();
// store hooks
const { captureEvent } = useEventTracker();
const {
instance: { instance },
} = useApplication();
const {
control,
@ -310,12 +313,14 @@ export const InviteMembers: React.FC<Props> = (props) => {
})
.then(async () => {
captureEvent(MEMBER_INVITED, {
emails: [
emails: !instance?.is_telemetry_anonymous
? [
...payload.emails.map((email) => ({
email: email.email,
role: getUserRole(email.role),
})),
],
]
: undefined,
project_id: undefined,
state: "SUCCESS",
element: "Onboarding",

View File

@ -69,7 +69,7 @@ export const ProjectMemberListItem: React.FC<Props> = observer((props) => {
captureEvent(PROJECT_MEMBER_REMOVED, {
member_id: userDetails.member.id,
role: getUserRole(userDetails.role as number),
removed_by_role: getUserRole(currentProjectRole as number),
removed_by_role: currentProjectRole ? getUserRole(currentProjectRole as number) : undefined,
state: "SUCCESS",
element: "Project settings members page",
});

View File

@ -26,24 +26,17 @@ const PostHogProvider: FC<IPosthogWrapper> = (props) => {
// router
const router = useRouter();
if (!isCloud && !telemetryEnabled) return <>{children}</>;
useEffect(() => {
if (user) {
// Identify sends an event, so you want may want to limit how often you call it
posthog?.identify(
isCloud ? user.email : user.id,
isCloud
? {
posthog?.identify(isCloud ? user.email : user.id, {
id: user.id,
first_name: user.first_name,
last_name: user.last_name,
email: user.email,
first_name: isCloud ? user.first_name : undefined,
last_name: isCloud ? user.last_name : undefined,
email: isCloud ? user.email : undefined,
use_case: user.use_case,
workspaces: workspaceIds,
}
: undefined
);
});
}
}, [user, workspaceIds, isCloud]);
@ -55,6 +48,7 @@ const PostHogProvider: FC<IPosthogWrapper> = (props) => {
autocapture: false,
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
});
posthog?.opt_in_capturing();
}
}, [posthogAPIKey, posthogHost, isCloud, telemetryEnabled]);
@ -80,6 +74,11 @@ const PostHogProvider: FC<IPosthogWrapper> = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (!isCloud && !telemetryEnabled) {
posthog?.opt_out_capturing();
return <>{children}</>;
}
if (posthogAPIKey) {
return <PHProvider client={posthog}>{children}</PHProvider>;
}

View File

@ -10,7 +10,7 @@ import { SendWorkspaceInvitationModal, WorkspaceMembersList } from "components/w
import { MEMBER_INVITED } from "constants/event-tracker";
import { EUserWorkspaceRoles } from "constants/workspace";
import { getUserRole } from "helpers/user.helper";
import { useEventTracker, useMember, useUser, useWorkspace } from "hooks/store";
import { useApplication, useEventTracker, useMember, useUser, useWorkspace } from "hooks/store";
// layouts
import { AppLayout } from "layouts/app-layout";
import { WorkspaceSettingLayout } from "layouts/settings-layout";
@ -31,6 +31,9 @@ const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
const { workspaceSlug } = router.query;
// store hooks
const { captureEvent } = useEventTracker();
const {
instance: { instance },
} = useApplication();
const {
membership: { currentWorkspaceRole },
} = useUser();
@ -42,16 +45,18 @@ const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
const handleWorkspaceInvite = (data: IWorkspaceBulkInviteFormData) => {
if (!workspaceSlug) return;
return inviteMembersToWorkspace(workspaceSlug.toString(), data)
.then(() => {
setInviteModal(false);
captureEvent(MEMBER_INVITED, {
emails: [
const emailsEventPayload = [
...data.emails.map((email) => ({
email: email.email,
role: getUserRole(email.role),
})),
],
];
return inviteMembersToWorkspace(workspaceSlug.toString(), data)
.then(() => {
setInviteModal(false);
captureEvent(MEMBER_INVITED, {
emails: !instance?.is_telemetry_anonymous ? emailsEventPayload : undefined,
project_id: undefined,
state: "SUCCESS",
element: "Workspace settings member page",
@ -64,12 +69,7 @@ const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
})
.catch((err) => {
captureEvent(MEMBER_INVITED, {
emails: [
...data.emails.map((email) => ({
email: email.email,
role: getUserRole(email.role),
})),
],
emails: !instance?.is_telemetry_anonymous ? emailsEventPayload : undefined,
project_id: undefined,
state: "FAILED",
element: "Workspace settings member page",

View File

@ -85,8 +85,7 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
joinWorkspaceMetricGroup(redirectWorkspace?.id);
captureEvent(MEMBER_ACCEPTED, {
member_id: invitation?.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
role: getUserRole(invitation?.role!),
role: invitation?.role ? getUserRole(invitation?.role) : undefined,
project_id: undefined,
accepted_from: "App",
state: "SUCCESS",

View File

@ -101,7 +101,9 @@ export class EventTrackerStore implements IEventTrackerStore {
return {
workspace_id: currentWorkspaceDetails?.id,
project_id: currentProjectDetails?.id,
user_project_role: getUserRole(currentProjectDetails?.member_role as number),
user_project_role: currentProjectDetails?.member_role
? getUserRole(currentProjectDetails?.member_role as number)
: undefined,
user_workspace_role: getUserRole(currentWorkspaceRole as number),
};
}