diff --git a/apps/app/pages/api/track-event.ts b/apps/app/pages/api/track-event.ts index 62944e4e5..0c3ec5dbe 100644 --- a/apps/app/pages/api/track-event.ts +++ b/apps/app/pages/api/track-event.ts @@ -38,7 +38,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) jitsu .id({ - ...user, + id: user.id, + email: user.email, + first_name: user.first_name, + last_name: user.last_name, }) .then(() => { jitsu.track(eventName, { diff --git a/apps/app/services/track-event.service.ts b/apps/app/services/track-event.service.ts index 936e14aa5..845a27cf1 100644 --- a/apps/app/services/track-event.service.ts +++ b/apps/app/services/track-event.service.ts @@ -1,7 +1,7 @@ // services import APIService from "services/api.service"; // types -import type { IWorkspace } from "types"; +import type { ICycle, IIssue, IModule, IProject, IState, IWorkspace } from "types"; // TODO: as we add more events, we can refactor this to be divided into different classes class TrackEventServices extends APIService { @@ -10,26 +10,36 @@ class TrackEventServices extends APIService { } async trackCreateWorkspaceEvent(data: IWorkspace): Promise { + const payload = { + workspaceId: data.id, + workspaceSlug: data.slug, + workspaceName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "CREATE_WORKSPACE", extra: { - ...data, + ...payload, }, }, }); } - async trackUpdateWorkspaceEvent(data: IWorkspace): Promise { + async trackUpdateWorkspaceEvent(data: Partial): Promise { + const payload = { + workspaceId: data.id, + workspaceSlug: data.slug, + workspaceName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "UPDATE_WORKSPACE", extra: { - ...data, + ...payload, }, }, }); @@ -48,27 +58,41 @@ class TrackEventServices extends APIService { }); } - async trackCreateProjectEvent(data: any): Promise { + async trackCreateProjectEvent(data: IProject): Promise { + const payload = { + workspaceId: data.workspace_detail.id, + workspaceName: data.workspace_detail.name, + workspaceSlug: data.workspace_detail.slug, + projectId: data.id, + projectName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "CREATE_PROJECT", extra: { - ...data, + ...payload, }, }, }); } - async trackUpdateProjectEvent(data: any): Promise { + async trackUpdateProjectEvent(data: Partial): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data.id, + projectName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "UPDATE_PROJECT", extra: { - ...data, + ...payload, }, }, }); @@ -139,27 +163,47 @@ class TrackEventServices extends APIService { }); } - async trackIssueCreateEvent(data: any): Promise { + async trackIssueCreateEvent(data: IIssue): Promise { + const payload = { + workspaceId: data.workspace_detail.id, + workspaceName: data.workspace_detail.name, + workspaceSlug: data.workspace_detail.slug, + projectId: data.project_detail.id, + projectName: data.project_detail.name, + projectIdentifier: data.project_detail.identifier, + issueId: data.id, + issueTitle: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "ISSUE_CREATE", extra: { - ...data, + ...payload, }, }, }); } - async trackIssueUpdateEvent(data: any): Promise { + async trackIssueUpdateEvent(data: Partial): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data?.project_detail?.name, + projectIdentifier: data?.project_detail?.identifier, + issueId: data.id, + issueTitle: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "ISSUE_UPDATE", extra: { - ...data, + ...payload, }, }, }); @@ -191,27 +235,47 @@ class TrackEventServices extends APIService { }); } - async trackStateCreateEvent(data: any): Promise { + async trackStateCreateEvent(data: IState): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data?.project_detail?.name, + projectIdentifier: data?.project_detail?.identifier, + stateId: data.id, + stateName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "STATE_CREATE", extra: { - ...data, + ...payload, }, }, }); } - async trackStateUpdateEvent(data: any): Promise { + async trackStateUpdateEvent(data: Partial): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data?.project_detail?.name, + projectIdentifier: data?.project_detail?.identifier, + stateId: data.id, + stateName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "STATE_UPDATE", extra: { - ...data, + ...payload, }, }, }); @@ -230,27 +294,47 @@ class TrackEventServices extends APIService { }); } - async trackCycleCreateEvent(data: any): Promise { + async trackCycleCreateEvent(data: ICycle): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data?.project_detail?.name, + projectIdentifier: data?.project_detail?.identifier, + cycleId: data.id, + cycleName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "CYCLE_CREATE", extra: { - ...data, + ...payload, }, }, }); } - async trackCycleUpdateEvent(data: any): Promise { + async trackCycleUpdateEvent(data: Partial): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data?.project_detail?.name, + projectIdentifier: data?.project_detail?.identifier, + cycleId: data.id, + cycleName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "CYCLE_UPDATE", extra: { - ...data, + ...payload, }, }, }); @@ -269,27 +353,45 @@ class TrackEventServices extends APIService { }); } - async trackModuleCreateEvent(data: any): Promise { + async trackModuleCreateEvent(data: IModule): Promise { + const payload = { + workspaceId: data?.workspace_detail.id, + workspaceName: data?.workspace_detail.name, + workspaceSlug: data?.workspace_detail.slug, + projectId: data?.project_detail?.id, + projectName: data.project_detail?.name, + moduleId: data.id, + moduleName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "MODULE_CREATE", extra: { - ...data, + ...payload, }, }, }); } - async trackModuleUpdateEvent(data: any): Promise { + async trackModuleUpdateEvent(data: Partial): Promise { + const payload = { + workspaceId: data?.workspace_detail?.id, + workspaceName: data?.workspace_detail?.name, + workspaceSlug: data?.workspace_detail?.slug, + projectId: data?.project_detail?.id, + projectName: data.project_detail?.name, + moduleId: data.id, + moduleName: data.name, + }; return this.request({ url: "/api/track-event", method: "POST", data: { eventName: "MODULE_UPDATE", extra: { - ...data, + ...payload, }, }, }); diff --git a/apps/app/types/cycles.d.ts b/apps/app/types/cycles.d.ts index 835be2bad..d39f0b140 100644 --- a/apps/app/types/cycles.d.ts +++ b/apps/app/types/cycles.d.ts @@ -1,4 +1,4 @@ -import type { IUser, IIssue } from "."; +import type { IUser, IIssue, IProject, IProjectLite, IWorkspace, IWorkspaceLite } from "types"; export interface ICycle { backlog_issues: number; @@ -14,6 +14,7 @@ export interface ICycle { name: string; owned_by: IUser; project: string; + project_detail: IProjectLite; start_date: string | null; started_issues: number; total_issues: number; @@ -21,6 +22,7 @@ export interface ICycle { updated_at: Date; updated_by: string; workspace: string; + workspace_detail: IWorkspaceLite; } export interface CurrentAndUpcomingCyclesResponse { diff --git a/apps/app/types/issues.d.ts b/apps/app/types/issues.d.ts index f3d2783bd..04c485b48 100644 --- a/apps/app/types/issues.d.ts +++ b/apps/app/types/issues.d.ts @@ -1,4 +1,13 @@ -import type { IState, IUser, IProject, ICycle, IModule, IUserLite } from "./"; +import type { + IState, + IUser, + IProject, + ICycle, + IModule, + IUserLite, + IProjectLite, + IWorkspaceLite, +} from "types"; export interface IIssueCycle { id: string; @@ -96,7 +105,7 @@ export interface IIssue { parent_detail: IIssueParent | null; priority: string | null; project: string; - project_detail: IProject; + project_detail: IProjectLite; sequence_id: number; sort_order: number; sprints: string | null; @@ -108,6 +117,7 @@ export interface IIssue { updated_at: Date; updated_by: string; workspace: string; + workspace_detail: IWorkspaceLite; labels: any[]; labels_list: string[]; } diff --git a/apps/app/types/modules.d.ts b/apps/app/types/modules.d.ts index b11d235bc..92f2ae199 100644 --- a/apps/app/types/modules.d.ts +++ b/apps/app/types/modules.d.ts @@ -1,4 +1,12 @@ -import type { IUser, IUserLite, IIssue, IProject } from "."; +import type { + IUser, + IUserLite, + IIssue, + IProject, + IWorkspace, + IWorkspaceLite, + IProjectLite, +} from "types"; export interface IModule { backlog_issues: number; @@ -28,7 +36,7 @@ export interface IModule { is_favorite: boolean; name: string; project: string; - project_detail: IProject; + project_detail: IProjectLite; start_date: string | null; started_issues: number; status: "backlog" | "planned" | "in-progress" | "paused" | "completed" | "cancelled" | null; @@ -38,6 +46,7 @@ export interface IModule { updated_at: Date; updated_by: string; workspace: string; + workspace_detail: IWorkspaceLite; } export interface ModuleIssueResponse { diff --git a/apps/app/types/projects.d.ts b/apps/app/types/projects.d.ts index 69f179dd5..dfd6c84fe 100644 --- a/apps/app/types/projects.d.ts +++ b/apps/app/types/projects.d.ts @@ -2,9 +2,10 @@ import type { IIssueFilterOptions, IUserLite, IWorkspace, + IWorkspaceLite, TIssueGroupByOptions, TIssueOrderByOptions, -} from "./"; +} from "types"; export interface IProject { cover_image: string | null; @@ -26,6 +27,13 @@ export interface IProject { updated_at: Date; updated_by: string; workspace: IWorkspace | string; + workspace_detail: IWorkspaceLite; +} + +export interface IProjectLite { + id: string; + name: string; + identifier: string; } export interface IFavoriteProject { diff --git a/apps/app/types/state.d.ts b/apps/app/types/state.d.ts index 29096c302..c0d9514c2 100644 --- a/apps/app/types/state.d.ts +++ b/apps/app/types/state.d.ts @@ -1,3 +1,5 @@ +import { IProject, IProjectLite, IWorkspaceLite } from "types"; + export interface IState { readonly id: string; color: string; @@ -8,11 +10,13 @@ export interface IState { group: "backlog" | "unstarted" | "started" | "completed" | "cancelled"; name: string; project: string; + readonly project_detail: IProjectLite; sequence: number; readonly slug: string; readonly updated_at: Date; readonly updated_by: string; workspace: string; + workspace_detail: IWorkspaceLite; } export interface StateResponse { diff --git a/apps/app/types/workspace.d.ts b/apps/app/types/workspace.d.ts index 6cfd12317..e31d8f481 100644 --- a/apps/app/types/workspace.d.ts +++ b/apps/app/types/workspace.d.ts @@ -1,4 +1,4 @@ -import type { IProjectMember, IUser, IUserLite } from "./"; +import type { IProjectMember, IUser, IUserLite } from "types"; export interface IWorkspace { readonly id: string; @@ -16,6 +16,12 @@ export interface IWorkspace { company_size: number | null; } +export interface IWorkspaceLite { + readonly id: string; + name: string; + slug: string; +} + export interface IWorkspaceMemberInvitation { readonly id: string; email: string;