chore: posthog event for workspace invite (#2989)

* chore: posthog event for workspace invite

* chore: updated event names, added all the existing events to workspace metrics group

* chore: seperated workspace invite

* fix: workspace invite accept event updated

---------

Co-authored-by: Ramesh Kumar Chandra <rameshkumar2299@gmail.com>
This commit is contained in:
Bavisetti Narayan 2023-12-06 17:15:14 +05:30 committed by Aaryan Khandelwal
parent ef01f01191
commit 0b01b439a0
25 changed files with 442 additions and 119 deletions

View File

@ -73,8 +73,7 @@ from plane.app.permissions import (
)
from plane.bgtasks.workspace_invitation_task import workspace_invitation
from plane.utils.issue_filters import issue_filters
from plane.utils.grouper import group_results
from plane.bgtasks.event_tracking_task import workspace_invite_event
class WorkSpaceViewSet(BaseViewSet):
model = Workspace
@ -407,6 +406,17 @@ class WorkspaceJoinEndpoint(BaseAPIView):
# Delete the invitation
workspace_invite.delete()
# Send event
if settings.POSTHOG_API_KEY and settings.POSTHOG_HOST:
workspace_invite_event.delay(
user=user.id if user is not None else None,
email=email,
user_agent=request.META.get("HTTP_USER_AGENT"),
ip=request.META.get("REMOTE_ADDR"),
event_name="MEMBER_ACCEPTED",
accepted_from="EMAIL",
)
return Response(
{"message": "Workspace Invitation Accepted"},

View File

@ -26,5 +26,25 @@ def auth_events(user, email, user_agent, ip, event_name, medium, first_time):
"first_time": first_time
}
)
except Exception as e:
capture_exception(e)
@shared_task
def workspace_invite_event(user, email, user_agent, ip, event_name, accepted_from):
try:
posthog = Posthog(settings.POSTHOG_API_KEY, host=settings.POSTHOG_HOST)
posthog.capture(
email,
event=event_name,
properties={
"event_id": uuid.uuid4().hex,
"user": {"email": email, "id": str(user)},
"device_ctx": {
"ip": ip,
"user_agent": user_agent,
},
"accepted_from": accepted_from
}
)
except Exception as e:
capture_exception(e)

View File

@ -6,7 +6,7 @@ import { useTheme } from "next-themes";
import { ProductUpdatesModal } from "components/common";
// ui
import { Breadcrumbs } from "@plane/ui";
// assetsˀ
// assets
import githubBlackImage from "/public/logos/github-black.png";
import githubWhiteImage from "/public/logos/github-white.png";

View File

@ -24,7 +24,7 @@ export const InboxIssueActivity: React.FC<Props> = observer(({ issueDetails }) =
const router = useRouter();
const { workspaceSlug, projectId, inboxIssueId } = router.query;
const { user: userStore } = useMobxStore();
const { user: userStore, trackEvent: { postHogEventTracker }, workspace: { currentWorkspace } } = useMobxStore();
const { setToastAlert } = useToast();
@ -42,7 +42,22 @@ export const InboxIssueActivity: React.FC<Props> = observer(({ issueDetails }) =
await issueCommentService
.patchIssueComment(workspaceSlug as string, projectId as string, inboxIssueId as string, commentId, data)
.then(() => mutateIssueActivity());
.then((res) => {
mutateIssueActivity();
postHogEventTracker(
"COMMENT_UPDATED",
{
...res,
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
}
);
};
const handleCommentDelete = async (commentId: string) => {
@ -52,7 +67,21 @@ export const InboxIssueActivity: React.FC<Props> = observer(({ issueDetails }) =
await issueCommentService
.deleteIssueComment(workspaceSlug as string, projectId as string, inboxIssueId as string, commentId)
.then(() => mutateIssueActivity());
.then(() => {
mutateIssueActivity();
postHogEventTracker(
"COMMENT_DELETED",
{
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
}
);
};
const handleAddComment = async (formData: IIssueComment) => {
@ -60,8 +89,20 @@ export const InboxIssueActivity: React.FC<Props> = observer(({ issueDetails }) =
await issueCommentService
.createIssueComment(workspaceSlug.toString(), issueDetails.project, issueDetails.id, formData)
.then(() => {
.then((res) => {
mutate(PROJECT_ISSUES_ACTIVITY(issueDetails.id));
postHogEventTracker(
"COMMENT_ADDED",
{
...res,
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch(() =>
setToastAlert({

View File

@ -62,6 +62,7 @@ export const CreateInboxIssueModal: React.FC<Props> = observer((props) => {
inboxIssueDetails: inboxIssueDetailsStore,
trackEvent: { postHogEventTracker },
appConfig: { envConfig },
workspace: { currentWorkspace }
} = useMobxStore();
const {
@ -91,16 +92,30 @@ export const CreateInboxIssueModal: React.FC<Props> = observer((props) => {
router.push(`/${workspaceSlug}/projects/${projectId}/inbox/${inboxId}?inboxIssueId=${res.issue_inbox[0].id}`);
handleClose();
} else reset(defaultValues);
postHogEventTracker("ISSUE_CREATE", {
...res,
state: "SUCCESS",
});
postHogEventTracker("ISSUE_CREATED",
{
...res,
state: "SUCCESS",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch((error) => {
console.log(error);
postHogEventTracker("ISSUE_CREATE", {
state: "FAILED",
});
postHogEventTracker("ISSUE_CREATED",
{
state: "FAILED",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
});
};
@ -214,9 +229,8 @@ export const CreateInboxIssueModal: React.FC<Props> = observer((props) => {
{issueName && issueName !== "" && (
<button
type="button"
className={`flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-custom-background-90 ${
iAmFeelingLucky ? "cursor-wait" : ""
}`}
className={`flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-custom-background-90 ${iAmFeelingLucky ? "cursor-wait" : ""
}`}
onClick={handleAutoGenerateDescription}
disabled={iAmFeelingLucky}
>
@ -296,7 +310,7 @@ export const CreateInboxIssueModal: React.FC<Props> = observer((props) => {
onClick={() => setCreateMore((prevData) => !prevData)}
>
<span className="text-xs">Create more</span>
<ToggleSwitch value={createMore} onChange={() => {}} size="md" />
<ToggleSwitch value={createMore} onChange={() => { }} size="md" />
</div>
<div className="flex items-center gap-2">
<Button variant="neutral-primary" size="sm" onClick={() => handleClose()}>

View File

@ -26,7 +26,7 @@ export const DeleteInboxIssueModal: React.FC<Props> = observer(({ isOpen, onClos
const router = useRouter();
const { workspaceSlug, projectId, inboxId } = router.query;
const { inboxIssueDetails: inboxIssueDetailsStore } = useMobxStore();
const { inboxIssueDetails: inboxIssueDetailsStore, trackEvent: { postHogEventTracker }, workspace: { currentWorkspace } } = useMobxStore();
const { setToastAlert } = useToast();
@ -48,7 +48,17 @@ export const DeleteInboxIssueModal: React.FC<Props> = observer(({ isOpen, onClos
title: "Success!",
message: "Issue deleted successfully.",
});
postHogEventTracker(
"ISSUE_DELETED",
{
state: "SUCCESS",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
)
// remove inboxIssueId from the url
router.push({
pathname: `/${workspaceSlug}/projects/${projectId}/inbox/${inboxId}`,
@ -56,12 +66,24 @@ export const DeleteInboxIssueModal: React.FC<Props> = observer(({ isOpen, onClos
handleClose();
})
.catch(() =>
.catch(() => {
setToastAlert({
type: "error",
title: "Error!",
message: "Issue could not be deleted. Please try again.",
})
postHogEventTracker(
"ISSUE_DELETED",
{
state: "FAILED",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
}
)
.finally(() => setIsDeleting(false));
};

View File

@ -24,7 +24,7 @@ export const IssueBlocksList: FC<Props> = (props) => {
{issueIds && issueIds.length > 0 ? (
issueIds.map((issueId: string) => (
<IssueBlock
key={issues[issueId].id}
key={issues[issueId]?.id}
columnId={columnId}
issue={issues[issueId]}
handleIssues={handleIssues}

View File

@ -54,6 +54,8 @@ export const IssueMainContent: React.FC<Props> = observer((props) => {
user: userStore,
project: projectStore,
projectState: { states },
trackEvent: { postHogEventTracker },
workspace: { currentWorkspace }
} = useMobxStore();
const user = userStore.currentUser ?? undefined;
const userRole = userStore.currentProjectRole;
@ -82,7 +84,22 @@ export const IssueMainContent: React.FC<Props> = observer((props) => {
await issueCommentService
.patchIssueComment(workspaceSlug as string, projectId as string, issueId as string, commentId, data)
.then(() => mutateIssueActivity());
.then((res) => {
mutateIssueActivity();
postHogEventTracker(
"COMMENT_UPDATED",
{
...res,
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
}
);
};
const handleCommentDelete = async (commentId: string) => {
@ -92,7 +109,21 @@ export const IssueMainContent: React.FC<Props> = observer((props) => {
await issueCommentService
.deleteIssueComment(workspaceSlug as string, projectId as string, issueId as string, commentId)
.then(() => mutateIssueActivity());
.then(() => {
mutateIssueActivity();
postHogEventTracker(
"COMMENT_DELETED",
{
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
}
);
};
const handleAddComment = async (formData: IIssueComment) => {
@ -100,8 +131,20 @@ export const IssueMainContent: React.FC<Props> = observer((props) => {
await issueCommentService
.createIssueComment(workspaceSlug.toString(), issueDetails.project, issueDetails.id, formData)
.then(() => {
.then((res) => {
mutate(PROJECT_ISSUES_ACTIVITY(issueDetails.id));
postHogEventTracker(
"COMMENT_ADDED",
{
...res,
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch(() =>
setToastAlert({

View File

@ -82,6 +82,7 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
moduleIssues: moduleIssueStore,
user: userStore,
trackEvent: { postHogEventTracker },
workspace: { currentWorkspace }
} = useMobxStore();
const user = userStore.currentUser;
@ -250,10 +251,16 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
title: "Success!",
message: "Issue created successfully.",
});
postHogEventTracker("ISSUE_CREATE", {
postHogEventTracker("ISSUE_CREATED", {
...res,
state: "SUCCESS",
});
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
if (payload.parent && payload.parent !== "") mutate(SUB_ISSUES(payload.parent));
}
})
@ -263,9 +270,15 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
title: "Error!",
message: "Issue could not be created. Please try again.",
});
postHogEventTracker("ISSUE_CREATE", {
postHogEventTracker("ISSUE_CREATED", {
state: "FAILED",
});
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
});
if (!createMore) onFormSubmitClose();
@ -317,10 +330,16 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
title: "Success!",
message: "Issue updated successfully.",
});
postHogEventTracker("ISSUE_UPDATE", {
postHogEventTracker("ISSUE_UPDATED", {
...res,
state: "SUCCESS",
});
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch(() => {
setToastAlert({
@ -328,9 +347,15 @@ export const CreateUpdateIssueModal: React.FC<IssuesModalProps> = observer((prop
title: "Error!",
message: "Issue could not be updated. Please try again.",
});
postHogEventTracker("ISSUE_UPDATE", {
postHogEventTracker("ISSUE_UPDATED", {
state: "FAILED",
});
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
});
};

View File

@ -26,7 +26,7 @@ export const DeleteModuleModal: React.FC<Props> = observer((props) => {
const router = useRouter();
const { workspaceSlug, projectId, moduleId, peekModule } = router.query;
const { module: moduleStore } = useMobxStore();
const { module: moduleStore, trackEvent: { postHogEventTracker } } = useMobxStore();
const { setToastAlert } = useToast();
@ -50,6 +50,12 @@ export const DeleteModuleModal: React.FC<Props> = observer((props) => {
title: "Success!",
message: "Module deleted successfully.",
});
postHogEventTracker(
"MODULE_DELETED",
{
state: 'SUCCESS'
}
);
})
.catch(() => {
setToastAlert({
@ -57,6 +63,12 @@ export const DeleteModuleModal: React.FC<Props> = observer((props) => {
title: "Error!",
message: "Module could not be deleted. Please try again.",
});
postHogEventTracker(
"MODULE_DELETED",
{
state: 'FAILED'
}
);
})
.finally(() => {
setIsDeleteLoading(false);

View File

@ -32,7 +32,7 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
const [activeProject, setActiveProject] = useState<string | null>(null);
const { project: projectStore, module: moduleStore } = useMobxStore();
const { project: projectStore, module: moduleStore, trackEvent: { postHogEventTracker } } = useMobxStore();
const projects = workspaceSlug ? projectStore.projects[workspaceSlug.toString()] : undefined;
@ -52,7 +52,7 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
const selectedProjectId = payload.project ?? projectId.toString();
await moduleStore
.createModule(workspaceSlug.toString(), selectedProjectId, payload)
.then(() => {
.then((res) => {
handleClose();
setToastAlert({
@ -60,6 +60,13 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
title: "Success!",
message: "Module created successfully.",
});
postHogEventTracker(
"MODULE_CREATED",
{
...res,
state: "SUCCESS"
}
);
})
.catch(() => {
setToastAlert({
@ -67,6 +74,12 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
title: "Error!",
message: "Module could not be created. Please try again.",
});
postHogEventTracker(
"MODULE_CREATED",
{
state: "FAILED"
}
);
});
};
@ -75,7 +88,7 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
const selectedProjectId = payload.project ?? projectId.toString();
await moduleStore
.updateModuleDetails(workspaceSlug.toString(), selectedProjectId, data.id, payload)
.then(() => {
.then((res) => {
handleClose();
setToastAlert({
@ -83,6 +96,13 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
title: "Success!",
message: "Module updated successfully.",
});
postHogEventTracker(
"MODULE_UPDATED",
{
...res,
state: "SUCCESS"
}
);
})
.catch(() => {
setToastAlert({
@ -90,6 +110,12 @@ export const CreateUpdateModuleModal: React.FC<Props> = observer((props) => {
title: "Error!",
message: "Module could not be updated. Please try again.",
});
postHogEventTracker(
"MODULE_UPDATED",
{
state: "FAILED"
}
);
});
};

View File

@ -62,7 +62,7 @@ export const Invitations: React.FC<Props> = (props) => {
await workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(async (res) => {
postHogEventTracker("WORKSPACE_USER_INVITE_ACCEPT", { ...res, state: "SUCCESS" });
postHogEventTracker("MEMBER_ACCEPTED", { ...res, state: "SUCCESS", accepted_from: "App" });
await workspaceStore.fetchWorkspaces();
await mutate(USER_WORKSPACES);
await updateLastWorkspace();
@ -71,7 +71,7 @@ export const Invitations: React.FC<Props> = (props) => {
})
.catch((error) => {
console.log(error);
postHogEventTracker("WORKSPACE_USER_INVITE_ACCEPT", { state: "FAILED" });
postHogEventTracker("MEMBER_ACCEPTED", { state: "FAILED", accepted_from: "App" });
})
.finally(() => setIsJoiningWorkspaces(false));
};
@ -88,11 +88,10 @@ export const Invitations: React.FC<Props> = (props) => {
return (
<div
key={invitation.id}
className={`flex cursor-pointer items-center gap-2 border p-3.5 rounded ${
isSelected
className={`flex cursor-pointer items-center gap-2 border p-3.5 rounded ${isSelected
? "border-custom-primary-100"
: "border-onboarding-border-200 hover:bg-onboarding-background-300/30"
}`}
}`}
onClick={() => handleInvitation(invitation, isSelected ? "withdraw" : "accepted")}
>
<div className="flex-shrink-0">

View File

@ -22,7 +22,7 @@ export const WorkspaceDashboardView = observer(() => {
user: userStore,
project: projectStore,
commandPalette: commandPaletteStore,
trackEvent: { setTrackElement },
trackEvent: { setTrackElement, postHogEventTracker },
} = useMobxStore();
const user = userStore.currentUser;
@ -37,7 +37,18 @@ export const WorkspaceDashboardView = observer(() => {
);
const handleTourCompleted = () => {
userStore.updateTourCompleted();
userStore.updateTourCompleted().then(() => {
postHogEventTracker(
"USER_TOUR_COMPLETE",
{
user_id: user?.id,
email: user?.email,
state: "SUCCESS"
}
)
}).catch((error) => {
console.log(error);
})
};
return (

View File

@ -9,8 +9,6 @@ import { PageForm } from "./page-form";
import { IPage } from "types";
// store
import { useMobxStore } from "lib/mobx/store-provider";
// helpers
import { trackEvent } from "helpers/event-tracker.helper";
type Props = {
data?: IPage | null;
@ -27,6 +25,8 @@ export const CreateUpdatePageModal: FC<Props> = (props) => {
// store
const {
page: { createPage, updatePage },
trackEvent: { postHogEventTracker },
workspace: { currentWorkspace }
} = useMobxStore();
const { setToastAlert } = useToast();
@ -47,10 +47,18 @@ export const CreateUpdatePageModal: FC<Props> = (props) => {
title: "Success!",
message: "Page created successfully.",
});
trackEvent("PAGE_CREATE", {
...res,
case: "SUCCESS",
});
postHogEventTracker(
"PAGE_CREATED",
{
...res,
state: "SUCCESS",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch(() => {
setToastAlert({
@ -58,9 +66,16 @@ export const CreateUpdatePageModal: FC<Props> = (props) => {
title: "Error!",
message: "Page could not be created. Please try again.",
});
trackEvent("PAGE_CREATE", {
case: "FAILED",
});
postHogEventTracker("PAGE_CREATED",
{
state: "FAILED",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
});
};
@ -75,10 +90,17 @@ export const CreateUpdatePageModal: FC<Props> = (props) => {
title: "Success!",
message: "Page updated successfully.",
});
trackEvent("PAGE_UPDATE", {
...res,
case: "SUCCESS",
});
postHogEventTracker("PAGE_UPDATED",
{
...res,
state: "SUCCESS",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch(() => {
setToastAlert({
@ -86,9 +108,16 @@ export const CreateUpdatePageModal: FC<Props> = (props) => {
title: "Error!",
message: "Page could not be updated. Please try again.",
});
trackEvent("PAGE_UPDATE", {
case: "FAILED",
});
postHogEventTracker("PAGE_UPDATED",
{
state: "FAILED",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
});
};

View File

@ -66,7 +66,8 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
const {
project: projectStore,
workspaceMember: { workspaceMembers },
trackEvent: { postHogEventTracker }
trackEvent: { postHogEventTracker },
workspace: { currentWorkspace },
} = useMobxStore();
// states
const [isChangeInIdentifierRequired, setIsChangeInIdentifierRequired] = useState(true);
@ -135,8 +136,13 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
state: "SUCCESS"
}
postHogEventTracker(
"PROJECT_CREATE",
"PROJECT_CREATED",
newPayload,
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: res.workspace
}
)
setToastAlert({
type: "success",
@ -156,10 +162,15 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
message: err.data[key],
});
postHogEventTracker(
"PROJECT_CREATE",
"PROJECT_CREATED",
{
state: "FAILED"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
)
}
);

View File

@ -12,7 +12,6 @@ import { Button, Input } from "@plane/ui";
import type { IProject } from "types";
// fetch-keys
import { useMobxStore } from "lib/mobx/store-provider";
import { trackEvent } from "helpers/event-tracker.helper";
type DeleteProjectModal = {
isOpen: boolean;
@ -28,7 +27,7 @@ const defaultValues = {
export const DeleteProjectModal: React.FC<DeleteProjectModal> = (props) => {
const { isOpen, project, onClose } = props;
// store
const { project: projectStore } = useMobxStore();
const { project: projectStore, workspace: { currentWorkspace }, trackEvent: { postHogEventTracker } } = useMobxStore();
// router
const router = useRouter();
const { workspaceSlug, projectId } = router.query;
@ -63,9 +62,17 @@ export const DeleteProjectModal: React.FC<DeleteProjectModal> = (props) => {
if (projectId && projectId.toString() === project.id) router.push(`/${workspaceSlug}/projects`);
handleClose();
trackEvent(
'DELETE_PROJECT'
)
postHogEventTracker(
'PROJECT_DELETED',
{
state: "SUCCESS"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
setToastAlert({
type: "success",
title: "Success!",
@ -73,9 +80,17 @@ export const DeleteProjectModal: React.FC<DeleteProjectModal> = (props) => {
});
})
.catch(() => {
trackEvent(
'DELETE_PROJECT/FAIL'
)
postHogEventTracker(
'PROJECT_DELETED',
{
state: "FAILED"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
setToastAlert({
type: "error",
title: "Error!",

View File

@ -28,7 +28,7 @@ const projectService = new ProjectService();
export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
const { project, workspaceSlug, isAdmin } = props;
// store
const { project: projectStore, trackEvent: { postHogEventTracker } } = useMobxStore();
const { project: projectStore, trackEvent: { postHogEventTracker }, workspace: { currentWorkspace } } = useMobxStore();
// toast
const { setToastAlert } = useToast();
// form data
@ -63,8 +63,13 @@ export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
.updateProject(workspaceSlug.toString(), project.id, payload)
.then((res) => {
postHogEventTracker(
'PROJECT_UPDATE',
{...res, state: "SUCCESS"}
'PROJECT_UPDATED',
{ ...res, state: "SUCCESS" },
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: res.workspace
}
);
setToastAlert({
type: "success",
@ -74,9 +79,14 @@ export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
})
.catch((error) => {
postHogEventTracker(
'PROJECT_UPDATE',
'PROJECT_UPDATED',
{
state: "FAILED"
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
setToastAlert({

View File

@ -57,6 +57,7 @@ export const SendProjectInvitationModal: React.FC<Props> = observer((props) => {
user: { currentProjectRole },
workspaceMember: { workspaceMembers },
trackEvent: { postHogEventTracker },
workspace: { currentWorkspace }
} = useMobxStore();
const {
@ -92,16 +93,30 @@ export const SendProjectInvitationModal: React.FC<Props> = observer((props) => {
type: "success",
message: "Member added successfully",
});
postHogEventTracker("PROJECT_MEMBER_INVITE", {
...res,
state: "SUCCESS",
});
postHogEventTracker("MEMBER_ADDED",
{
...res,
state: "SUCCESS",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.catch((error) => {
console.log(error);
postHogEventTracker("PROJECT_MEMBER_INVITE", {
state: "FAILED",
});
postHogEventTracker("MEMBER_ADDED",
{
state: "FAILED",
},
{
isGrouping: true,
groupType: "Workspace_metrics",
gorupId: currentWorkspace?.id!
}
);
})
.finally(() => {
reset(defaultValues);

View File

@ -72,7 +72,7 @@ export const CreateWorkspaceForm: FC<Props> = observer((props) => {
.createWorkspace(formData)
.then(async (res) => {
postHogEventTracker(
"WORKSPACE_CREATE",
"WORKSPACE_CREATED",
{
...res,
state: "SUCCESS"
@ -94,7 +94,7 @@ export const CreateWorkspaceForm: FC<Props> = observer((props) => {
message: "Workspace could not be created. Please try again.",
})
postHogEventTracker(
"WORKSPACE_CREATE",
"WORKSPACE_CREATED",
{
state: "FAILED"
},
@ -110,7 +110,7 @@ export const CreateWorkspaceForm: FC<Props> = observer((props) => {
message: "Some error occurred while creating workspace. Please try again.",
});
postHogEventTracker(
"WORKSPACE_CREATE",
"WORKSPACE_CREATED",
{
state: "FAILED"
},

View File

@ -63,7 +63,7 @@ export const DeleteWorkspaceModal: React.FC<Props> = observer((props) => {
.then((res) => {
handleClose();
router.push("/");
postHogEventTracker("WORKSPACE_DELETE", {
postHogEventTracker("WORKSPACE_DELETED", {
res,
state: "SUCCESS",
});
@ -79,7 +79,7 @@ export const DeleteWorkspaceModal: React.FC<Props> = observer((props) => {
title: "Error!",
message: "Something went wrong. Please try again later.",
});
postHogEventTracker("WORKSPACE_DELETE", {
postHogEventTracker("WORKSPACE_DELETED", {
state: "FAILED",
});
});

View File

@ -67,7 +67,7 @@ export const WorkspaceDetails: FC = observer(() => {
await updateWorkspace(currentWorkspace.slug, payload)
.then((res) => {
postHogEventTracker("WORKSPACE_UPDATE", {
postHogEventTracker("WORKSPACE_UPDATED", {
...res,
state: "SUCCESS",
});
@ -78,7 +78,7 @@ export const WorkspaceDetails: FC = observer(() => {
});
})
.catch((err) => {
postHogEventTracker("WORKSPACE_UPDATE", {
postHogEventTracker("WORKSPACE_UPDATED", {
state: "FAILED",
});
console.error(err);

View File

@ -41,7 +41,7 @@ const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
return inviteMembersToWorkspace(workspaceSlug.toString(), data)
.then(async (res) => {
setInviteModal(false);
postHogEventTracker("WORKSPACE_USER_INVITE", { ...res, state: "SUCCESS" });
postHogEventTracker("MEMBER_INVITED", { ...res, state: "SUCCESS" });
setToastAlert({
type: "success",
title: "Success!",
@ -49,7 +49,7 @@ const WorkspaceMembersSettingsPage: NextPageWithLayout = observer(() => {
});
})
.catch((err) => {
postHogEventTracker("WORKSPACE_USER_INVITE", { state: "FAILED" });
postHogEventTracker("MEMBER_INVITED", { state: "FAILED" });
setToastAlert({
type: "error",
title: "Error!",

View File

@ -46,6 +46,7 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
const {
workspace: { workspaceSlug },
user: { currentUserSettings },
trackEvent: { postHogEventTracker }
} = useMobxStore();
const router = useRouter();
@ -88,10 +89,18 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(() => {
.then((res) => {
mutate("USER_WORKSPACES");
const firstInviteId = invitationsRespond[0];
const redirectWorkspace = invitations?.find((i) => i.id === firstInviteId)?.workspace;
postHogEventTracker(
"MEMBER_ACCEPTED",
{
...res,
state: "SUCCESS",
accepted_from: "App"
}
);
userService
.updateUser({ last_workspace_id: redirectWorkspace?.id })
.then(() => {
@ -147,11 +156,10 @@ const UserInvitationsPage: NextPageWithLayout = observer(() => {
return (
<div
key={invitation.id}
className={`flex cursor-pointer items-center gap-2 border py-5 px-3.5 rounded ${
isSelected
className={`flex cursor-pointer items-center gap-2 border py-5 px-3.5 rounded ${isSelected
? "border-custom-primary-100"
: "border-custom-border-200 hover:bg-custom-background-80"
}`}
}`}
onClick={() => handleInvitation(invitation, isSelected ? "withdraw" : "accepted")}
>
<div className="flex-shrink-0">

View File

@ -36,6 +36,7 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
const {
user: { currentUser, updateCurrentUser, updateUserOnBoard },
workspace: workspaceStore,
trackEvent: { postHogEventTracker }
} = useMobxStore();
const router = useRouter();
@ -77,7 +78,19 @@ const OnboardingPage: NextPageWithLayout = observer(() => {
const finishOnboarding = async () => {
if (!user || !workspaces) return;
await updateUserOnBoard();
await updateUserOnBoard().then(() => {
postHogEventTracker(
"USER_ONBOARDING_COMPLETE",
{
user_role: user.role,
email: user.email,
user_id: user.id,
status: "SUCCESS"
}
)
}).catch((error) => {
console.log(error);
})
router.replace(`/${workspaces[0].slug}`);
};

View File

@ -7,8 +7,8 @@ export interface ITrackEventStore {
setTrackElement: (element: string) => void;
postHogEventTracker: (
eventName: string,
payload: object | [] | null
// group: { isGrouping: boolean; groupType: string; gorupId: string } | null
payload: object | [] | null,
group?: { isGrouping: boolean | null; groupType: string | null; gorupId: string | null } | null
) => void;
}
@ -30,8 +30,8 @@ export class TrackEventStore implements ITrackEventStore {
postHogEventTracker = (
eventName: string,
payload: object | [] | null
// group: { isGrouping: boolean; groupType: string; gorupId: string } | null
payload: object | [] | null,
group?: { isGrouping: boolean | null; groupType: string | null; gorupId: string | null } | null
) => {
try {
console.log("POSTHOG_EVENT: ", eventName);
@ -43,7 +43,7 @@ export class TrackEventStore implements ITrackEventStore {
project_id: this.rootStore.project.currentProjectDetails?.id ?? "",
project_identifier: this.rootStore.project.currentProjectDetails?.identifier ?? "",
};
if (["PROJECT_CREATE", "PROJECT_UPDATE"].includes(eventName)) {
if (["PROJECT_CREATED", "PROJECT_UPDATED"].includes(eventName)) {
const project_details: any = payload as object;
extras = {
...extras,
@ -53,24 +53,23 @@ export class TrackEventStore implements ITrackEventStore {
};
}
// if (group!.isGrouping === true) {
// posthog?.group(group!.groupType, group!.gorupId, {
// name: "PostHog",
// subscription: "subscription",
// date_joined: "2020-01-23T00:00:00.000Z",
// });
// console.log("END OF GROUPING");
// posthog?.capture(eventName, {
// ...payload,
// element: this.trackElement ?? "",
// });
// } else {
posthog?.capture(eventName, {
...payload,
extras: extras,
element: this.trackElement ?? "",
});
// }
if (group && group!.isGrouping === true) {
posthog?.group(group!.groupType!, group!.gorupId!, {
date: new Date(),
workspace_id: group!.gorupId,
});
posthog?.capture(eventName, {
...payload,
extras: extras,
element: this.trackElement ?? "",
});
} else {
posthog?.capture(eventName, {
...payload,
extras: extras,
element: this.trackElement ?? "",
});
}
console.log(payload);
} catch (error) {
console.log(error);