2023-03-29 06:54:19 +00:00
|
|
|
// services
|
|
|
|
import APIService from "services/api.service";
|
2023-03-30 13:57:46 +00:00
|
|
|
|
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
// types
|
2023-03-30 13:57:46 +00:00
|
|
|
import type {
|
2023-06-06 16:06:00 +00:00
|
|
|
ICurrentUserResponse,
|
2023-03-30 13:57:46 +00:00
|
|
|
ICycle,
|
2023-05-05 10:15:38 +00:00
|
|
|
IEstimate,
|
2023-03-30 13:57:46 +00:00
|
|
|
IGptResponse,
|
|
|
|
IIssue,
|
2023-04-06 06:38:52 +00:00
|
|
|
IIssueComment,
|
2023-03-30 13:57:46 +00:00
|
|
|
IModule,
|
|
|
|
IPage,
|
|
|
|
IPageBlock,
|
|
|
|
IProject,
|
|
|
|
IState,
|
2023-04-03 09:34:48 +00:00
|
|
|
IView,
|
2023-03-30 13:57:46 +00:00
|
|
|
IWorkspace,
|
|
|
|
} from "types";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type WorkspaceEventType =
|
|
|
|
| "CREATE_WORKSPACE"
|
|
|
|
| "UPDATE_WORKSPACE"
|
|
|
|
| "DELETE_WORKSPACE"
|
|
|
|
| "WORKSPACE_USER_INVITE"
|
|
|
|
| "WORKSPACE_USER_INVITE_ACCEPT"
|
|
|
|
| "WORKSPACE_USER_BULK_INVITE_ACCEPT";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-04-06 06:38:52 +00:00
|
|
|
type ProjectEventType =
|
|
|
|
| "CREATE_PROJECT"
|
|
|
|
| "UPDATE_PROJECT"
|
|
|
|
| "DELETE_PROJECT"
|
|
|
|
| "PROJECT_MEMBER_INVITE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type IssueEventType = "ISSUE_CREATE" | "ISSUE_UPDATE" | "ISSUE_DELETE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type CycleEventType = "CYCLE_CREATE" | "CYCLE_UPDATE" | "CYCLE_DELETE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type StateEventType = "STATE_CREATE" | "STATE_UPDATE" | "STATE_DELETE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type ModuleEventType = "MODULE_CREATE" | "MODULE_UPDATE" | "MODULE_DELETE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type PagesEventType = "PAGE_CREATE" | "PAGE_UPDATE" | "PAGE_DELETE";
|
2023-03-29 06:54:19 +00:00
|
|
|
|
2023-04-03 09:34:48 +00:00
|
|
|
type ViewEventType = "VIEW_CREATE" | "VIEW_UPDATE" | "VIEW_DELETE";
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
type IssueCommentEventType =
|
|
|
|
| "ISSUE_COMMENT_CREATE"
|
|
|
|
| "ISSUE_COMMENT_UPDATE"
|
|
|
|
| "ISSUE_COMMENT_DELETE";
|
2023-04-06 06:38:52 +00:00
|
|
|
|
2023-06-16 13:27:17 +00:00
|
|
|
type Toggle =
|
|
|
|
| "TOGGLE_CYCLE"
|
|
|
|
| "TOGGLE_MODULE"
|
|
|
|
| "TOGGLE_VIEW"
|
|
|
|
| "TOGGLE_PAGES"
|
|
|
|
| "TOGGLE_STATE"
|
|
|
|
| "TOGGLE_INBOX";
|
|
|
|
|
|
|
|
export type MiscellaneousEventType = `${Toggle}_ON` | `${Toggle}_OFF`;
|
2023-04-06 06:38:52 +00:00
|
|
|
|
|
|
|
type IntegrationEventType = "ADD_WORKSPACE_INTEGRATION" | "REMOVE_WORKSPACE_INTEGRATION";
|
|
|
|
|
|
|
|
type GitHubSyncEventType = "GITHUB_REPO_SYNC";
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type PageBlocksEventType =
|
|
|
|
| "PAGE_BLOCK_CREATE"
|
|
|
|
| "PAGE_BLOCK_UPDATE"
|
|
|
|
| "PAGE_BLOCK_DELETE"
|
|
|
|
| "PAGE_BLOCK_CONVERTED_TO_ISSUE";
|
|
|
|
|
2023-04-06 06:38:52 +00:00
|
|
|
type IssueLabelEventType = "ISSUE_LABEL_CREATE" | "ISSUE_LABEL_UPDATE" | "ISSUE_LABEL_DELETE";
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
type GptEventType = "ASK_GPT" | "USE_GPT_RESPONSE_IN_ISSUE" | "USE_GPT_RESPONSE_IN_PAGE_BLOCK";
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
type IssueEstimateEventType = "ESTIMATE_CREATE" | "ESTIMATE_UPDATE" | "ESTIMATE_DELETE";
|
|
|
|
|
2023-06-16 13:27:17 +00:00
|
|
|
type InboxEventType =
|
|
|
|
| "INBOX_CREATE"
|
|
|
|
| "INBOX_UPDATE"
|
|
|
|
| "INBOX_DELETE"
|
|
|
|
| "INBOX_ISSUE_CREATE"
|
|
|
|
| "INBOX_ISSUE_UPDATE"
|
|
|
|
| "INBOX_ISSUE_DELETE"
|
|
|
|
| "INBOX_ISSUE_DUPLICATED"
|
|
|
|
| "INBOX_ISSUE_ACCEPTED"
|
|
|
|
| "INBOX_ISSUE_SNOOZED"
|
|
|
|
| "INBOX_ISSUE_REJECTED";
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
type ImporterEventType =
|
|
|
|
| "GITHUB_IMPORTER_CREATE"
|
|
|
|
| "GITHUB_IMPORTER_DELETE"
|
|
|
|
| "JIRA_IMPORTER_CREATE"
|
|
|
|
| "JIRA_IMPORTER_DELETE";
|
2023-05-25 07:08:53 +00:00
|
|
|
|
|
|
|
type AnalyticsEventType =
|
|
|
|
| "WORKSPACE_SCOPE_AND_DEMAND_ANALYTICS"
|
|
|
|
| "WORKSPACE_CUSTOM_ANALYTICS"
|
|
|
|
| "WORKSPACE_ANALYTICS_EXPORT"
|
|
|
|
| "PROJECT_SCOPE_AND_DEMAND_ANALYTICS"
|
|
|
|
| "PROJECT_CUSTOM_ANALYTICS"
|
|
|
|
| "PROJECT_ANALYTICS_EXPORT"
|
|
|
|
| "CYCLE_SCOPE_AND_DEMAND_ANALYTICS"
|
|
|
|
| "CYCLE_CUSTOM_ANALYTICS"
|
|
|
|
| "CYCLE_ANALYTICS_EXPORT"
|
|
|
|
| "MODULE_SCOPE_AND_DEMAND_ANALYTICS"
|
|
|
|
| "MODULE_CUSTOM_ANALYTICS"
|
|
|
|
| "MODULE_ANALYTICS_EXPORT";
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
class TrackEventServices extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super("/");
|
2023-03-29 06:54:19 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackWorkspaceEvent(
|
|
|
|
data: IWorkspace | any,
|
|
|
|
eventName: WorkspaceEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (
|
|
|
|
eventName !== "DELETE_WORKSPACE" &&
|
|
|
|
eventName !== "WORKSPACE_USER_INVITE" &&
|
|
|
|
eventName !== "WORKSPACE_USER_INVITE_ACCEPT" &&
|
|
|
|
eventName !== "WORKSPACE_USER_BULK_INVITE_ACCEPT"
|
|
|
|
)
|
|
|
|
payload = {
|
|
|
|
workspaceId: data.id,
|
|
|
|
workspaceSlug: data.slug,
|
|
|
|
workspaceName: data.name,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-30 13:57:46 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackProjectEvent(
|
|
|
|
data: Partial<IProject> | any,
|
2023-06-06 16:06:00 +00:00
|
|
|
eventName: ProjectEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-30 13:57:46 +00:00
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
2023-04-06 06:38:52 +00:00
|
|
|
if (eventName !== "DELETE_PROJECT" && eventName !== "PROJECT_MEMBER_INVITE")
|
2023-03-30 13:57:46 +00:00
|
|
|
payload = {
|
|
|
|
workspaceId: data?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.workspace_detail?.slug,
|
|
|
|
projectId: data?.id,
|
|
|
|
projectName: data?.name,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-30 13:57:46 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackUserOnboardingCompleteEvent(
|
|
|
|
data: any,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: "USER_ONBOARDING_COMPLETE",
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackIssueEvent(
|
|
|
|
data: IIssue | any,
|
|
|
|
eventName: IssueEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "ISSUE_DELETE")
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
else payload = data;
|
2023-03-29 06:54:19 +00:00
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackIssueMarkedAsDoneEvent(
|
|
|
|
data: any,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-06 06:38:52 +00:00
|
|
|
if (!trackEvent) return;
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: "ISSUES_MARKED_AS_DONE",
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async trackIssuePartialPropertyUpdateEvent(
|
|
|
|
data: any,
|
|
|
|
propertyName:
|
|
|
|
| "ISSUE_PROPERTY_UPDATE_PRIORITY"
|
|
|
|
| "ISSUE_PROPERTY_UPDATE_STATE"
|
|
|
|
| "ISSUE_PROPERTY_UPDATE_ASSIGNEE"
|
|
|
|
| "ISSUE_PROPERTY_UPDATE_DUE_DATE"
|
2023-06-06 16:06:00 +00:00
|
|
|
| "ISSUE_PROPERTY_UPDATE_ESTIMATE",
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-06 06:38:52 +00:00
|
|
|
): Promise<any> {
|
|
|
|
if (!trackEvent) return;
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: propertyName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async trackIssueCommentEvent(
|
|
|
|
data: Partial<IIssueComment> | any,
|
2023-06-06 16:06:00 +00:00
|
|
|
eventName: IssueCommentEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-06 06:38:52 +00:00
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "ISSUE_COMMENT_DELETE")
|
|
|
|
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?.issue,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...payload,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async trackIssueMovedToCycleOrModuleEvent(
|
|
|
|
data: any,
|
|
|
|
eventName:
|
|
|
|
| "ISSUE_MOVED_TO_CYCLE"
|
|
|
|
| "ISSUE_MOVED_TO_MODULE"
|
|
|
|
| "ISSUE_MOVED_TO_CYCLE_IN_BULK"
|
2023-06-06 16:06:00 +00:00
|
|
|
| "ISSUE_MOVED_TO_MODULE_IN_BULK",
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-04-06 06:38:52 +00:00
|
|
|
): Promise<any> {
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackIssueBulkDeleteEvent(data: any, user: ICurrentUserResponse | undefined): Promise<any> {
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: "ISSUE_BULK_DELETE",
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackIssueLabelEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: IssueLabelEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-06 06:38:52 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackStateEvent(
|
|
|
|
data: IState | any,
|
|
|
|
eventName: StateEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "STATE_DELETE")
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackCycleEvent(
|
|
|
|
data: ICycle | any,
|
|
|
|
eventName: CycleEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "CYCLE_DELETE")
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackModuleEvent(
|
|
|
|
data: IModule | any,
|
|
|
|
eventName: ModuleEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "MODULE_DELETE")
|
|
|
|
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,
|
|
|
|
moduleId: data.id,
|
|
|
|
};
|
|
|
|
else payload = data;
|
2023-03-29 06:54:19 +00:00
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackPageEvent(
|
|
|
|
data: Partial<IPage> | any,
|
|
|
|
eventName: PagesEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "PAGE_DELETE")
|
|
|
|
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,
|
|
|
|
pageId: data.id,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackPageBlockEvent(
|
|
|
|
data: Partial<IPageBlock> | IIssue,
|
2023-06-06 16:06:00 +00:00
|
|
|
eventName: PageBlocksEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-30 13:57:46 +00:00
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "PAGE_BLOCK_DELETE" && eventName !== "PAGE_BLOCK_CONVERTED_TO_ISSUE")
|
|
|
|
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,
|
|
|
|
pageId: (data as IPageBlock)?.page,
|
|
|
|
pageBlockId: data.id,
|
|
|
|
};
|
|
|
|
else if (eventName === "PAGE_BLOCK_CONVERTED_TO_ISSUE") {
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
} else payload = data;
|
2023-03-29 06:54:19 +00:00
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackAskGptEvent(
|
|
|
|
data: IGptResponse,
|
|
|
|
eventName: GptEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-29 09:08:30 +00:00
|
|
|
const payload = {
|
|
|
|
workspaceId: data?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.workspace_detail?.slug,
|
|
|
|
projectId: data?.project_detail?.id,
|
2023-03-30 13:57:46 +00:00
|
|
|
projectIdentifier: data?.project_detail?.identifier,
|
|
|
|
projectName: data?.project_detail?.name,
|
|
|
|
count: data?.count,
|
2023-03-29 09:08:30 +00:00
|
|
|
};
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackUseGPTResponseEvent(
|
|
|
|
data: IIssue | IPageBlock,
|
|
|
|
eventName: GptEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-03-30 13:57:46 +00:00
|
|
|
if (!trackEvent) return;
|
|
|
|
|
|
|
|
let payload: any;
|
|
|
|
|
|
|
|
if (eventName === "USE_GPT_RESPONSE_IN_ISSUE") {
|
|
|
|
payload = {
|
|
|
|
workspaceId: data?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.workspace_detail?.slug,
|
|
|
|
projectId: data?.project_detail?.id,
|
|
|
|
projectIdentifier: data?.project_detail?.identifier,
|
|
|
|
projectName: data?.project_detail?.name,
|
|
|
|
issueId: data.id,
|
|
|
|
};
|
|
|
|
} else if (eventName === "USE_GPT_RESPONSE_IN_PAGE_BLOCK") {
|
|
|
|
payload = {
|
|
|
|
workspaceId: data?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.workspace_detail?.slug,
|
|
|
|
projectId: data?.project_detail?.id,
|
|
|
|
projectIdentifier: data?.project_detail?.identifier,
|
|
|
|
projectName: data?.project_detail?.name,
|
|
|
|
pageId: (data as IPageBlock)?.page,
|
|
|
|
pageBlockId: data.id,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
2023-03-30 13:57:46 +00:00
|
|
|
eventName,
|
2023-03-29 06:54:19 +00:00
|
|
|
extra: {
|
2023-03-30 13:57:46 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-04-03 09:34:48 +00:00
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackViewEvent(
|
|
|
|
data: IView,
|
|
|
|
eventName: ViewEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-03 09:34:48 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName === "VIEW_DELETE") payload = data;
|
|
|
|
else
|
|
|
|
payload = {
|
|
|
|
labels: Boolean(data.query_data.labels),
|
|
|
|
assignees: Boolean(data.query_data.assignees),
|
|
|
|
priority: Boolean(data.query_data.priority),
|
|
|
|
state: Boolean(data.query_data.state),
|
|
|
|
created_by: Boolean(data.query_data.created_by),
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...payload,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-03 09:34:48 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-04-06 06:38:52 +00:00
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackMiscellaneousEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: MiscellaneousEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-06 06:38:52 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackAppIntegrationEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: IntegrationEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-06 06:38:52 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackGitHubSyncEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: GitHubSyncEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-04-06 06:38:52 +00:00
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-04-06 06:38:52 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-05-05 10:15:38 +00:00
|
|
|
|
|
|
|
async trackIssueEstimateEvent(
|
|
|
|
data: { estimate: IEstimate },
|
2023-06-06 16:06:00 +00:00
|
|
|
eventName: IssueEstimateEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-05-05 10:15:38 +00:00
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
|
|
|
if (eventName === "ESTIMATE_DELETE") payload = data;
|
|
|
|
else
|
|
|
|
payload = {
|
|
|
|
workspaceId: data?.estimate?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.estimate?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.estimate?.workspace_detail?.slug,
|
|
|
|
projectId: data?.estimate?.project_detail?.id,
|
|
|
|
projectName: data?.estimate?.project_detail?.name,
|
|
|
|
projectIdentifier: data?.estimate?.project_detail?.identifier,
|
|
|
|
estimateId: data.estimate?.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...payload,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-05-05 10:15:38 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackImporterEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: ImporterEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-05-05 10:15:38 +00:00
|
|
|
let payload: any;
|
|
|
|
if (eventName === "GITHUB_IMPORTER_DELETE" || eventName === "JIRA_IMPORTER_DELETE")
|
|
|
|
payload = data;
|
|
|
|
else
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...payload,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-05-05 10:15:38 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-05-25 07:08:53 +00:00
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
async trackAnalyticsEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: AnalyticsEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
2023-05-25 07:08:53 +00:00
|
|
|
const payload = { ...data };
|
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: payload,
|
2023-06-06 16:06:00 +00:00
|
|
|
user: user,
|
2023-05-25 07:08:53 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-06-16 13:27:17 +00:00
|
|
|
|
|
|
|
// TODO: add types to the data
|
|
|
|
async trackInboxEvent(
|
|
|
|
data: any,
|
|
|
|
eventName: InboxEventType,
|
|
|
|
user: ICurrentUserResponse | undefined
|
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "INBOX_DELETE")
|
|
|
|
payload = {
|
|
|
|
issue: data?.issue?.id,
|
|
|
|
inbox: data?.id,
|
|
|
|
workspaceId: data?.issue?.workspace_detail?.id,
|
|
|
|
workspaceName: data?.issue?.workspace_detail?.name,
|
|
|
|
workspaceSlug: data?.issue?.workspace_detail?.slug,
|
|
|
|
projectId: data?.issue?.project_detail?.id,
|
|
|
|
projectName: data?.issue?.project_detail?.name,
|
|
|
|
};
|
|
|
|
else payload = data;
|
|
|
|
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName,
|
|
|
|
extra: {
|
|
|
|
...payload,
|
|
|
|
},
|
|
|
|
user: user,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-03-29 06:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const trackEventServices = new TrackEventServices();
|
|
|
|
|
|
|
|
export default trackEventServices;
|