From b35874e294be76088dd983ea3179dde46d100e47 Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:15:14 +0530 Subject: [PATCH] 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 --- apiserver/plane/app/views/workspace.py | 14 ++++- .../plane/bgtasks/event_tracking_task.py | 20 ++++++ .../headers/workspace-dashboard.tsx | 2 - web/components/inbox/issue-activity.tsx | 49 +++++++++++++-- .../inbox/modals/create-issue-modal.tsx | 36 +++++++---- .../inbox/modals/delete-issue-modal.tsx | 28 ++++++++- .../issues/issue-layouts/list/blocks-list.tsx | 2 +- web/components/issues/main-content.tsx | 49 ++++++++++++++- web/components/issues/modal.tsx | 41 ++++++++++--- .../modules/delete-module-modal.tsx | 14 ++++- web/components/modules/modal.tsx | 32 +++++++++- web/components/onboarding/invitations.tsx | 9 ++- .../page-views/workspace-dashboard.tsx | 15 ++++- .../pages/create-update-page-modal.tsx | 61 ++++++++++++++----- .../project/create-project-modal.tsx | 17 +++++- .../project/delete-project-modal.tsx | 31 +++++++--- web/components/project/form.tsx | 18 ++++-- .../project/send-project-invitation-modal.tsx | 29 ++++++--- .../workspace/create-workspace-form.tsx | 6 +- .../workspace/delete-workspace-modal.tsx | 4 +- .../workspace/settings/workspace-details.tsx | 4 +- .../[workspaceSlug]/settings/members.tsx | 4 +- web/pages/invitations/index.tsx | 16 +++-- web/pages/onboarding/index.tsx | 15 ++++- web/store/event-tracker.store.ts | 45 +++++++------- 25 files changed, 441 insertions(+), 120 deletions(-) diff --git a/apiserver/plane/app/views/workspace.py b/apiserver/plane/app/views/workspace.py index 108b89f21..5e50f28f0 100644 --- a/apiserver/plane/app/views/workspace.py +++ b/apiserver/plane/app/views/workspace.py @@ -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"}, diff --git a/apiserver/plane/bgtasks/event_tracking_task.py b/apiserver/plane/bgtasks/event_tracking_task.py index 2e579bca1..25479d3ee 100644 --- a/apiserver/plane/bgtasks/event_tracking_task.py +++ b/apiserver/plane/bgtasks/event_tracking_task.py @@ -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) \ No newline at end of file diff --git a/web/components/headers/workspace-dashboard.tsx b/web/components/headers/workspace-dashboard.tsx index eeff05ba7..76bd6bc30 100644 --- a/web/components/headers/workspace-dashboard.tsx +++ b/web/components/headers/workspace-dashboard.tsx @@ -8,11 +8,9 @@ import githubWhiteImage from "/public/logos/github-white.png"; // components import { ProductUpdatesModal } from "components/common"; import { Breadcrumbs } from "@plane/ui"; -import { useMobxStore } from "lib/mobx/store-provider"; export const WorkspaceDashboardHeader = () => { const [isProductUpdatesModalOpen, setIsProductUpdatesModalOpen] = useState(false); - const { trackEvent: { postHogEventTracker } } = useMobxStore(); // theme const { resolvedTheme } = useTheme(); diff --git a/web/components/inbox/issue-activity.tsx b/web/components/inbox/issue-activity.tsx index d8d68313b..c653653ab 100644 --- a/web/components/inbox/issue-activity.tsx +++ b/web/components/inbox/issue-activity.tsx @@ -24,7 +24,7 @@ export const InboxIssueActivity: React.FC = 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 = 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 = 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 = 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({ diff --git a/web/components/inbox/modals/create-issue-modal.tsx b/web/components/inbox/modals/create-issue-modal.tsx index 0ab6b3d85..959bc306f 100644 --- a/web/components/inbox/modals/create-issue-modal.tsx +++ b/web/components/inbox/modals/create-issue-modal.tsx @@ -62,6 +62,7 @@ export const CreateInboxIssueModal: React.FC = observer((props) => { inboxIssueDetails: inboxIssueDetailsStore, trackEvent: { postHogEventTracker }, appConfig: { envConfig }, + workspace: { currentWorkspace } } = useMobxStore(); const { @@ -91,16 +92,30 @@ export const CreateInboxIssueModal: React.FC = 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 = observer((props) => { {issueName && issueName !== "" && (