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 {
|
|
|
|
ICycle,
|
|
|
|
IGptResponse,
|
|
|
|
IIssue,
|
|
|
|
IModule,
|
|
|
|
IPage,
|
|
|
|
IPageBlock,
|
|
|
|
IProject,
|
|
|
|
IState,
|
|
|
|
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-03-30 13:57:46 +00:00
|
|
|
type ProjectEventType = "CREATE_PROJECT" | "UPDATE_PROJECT" | "DELETE_PROJECT";
|
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-03-30 13:57:46 +00:00
|
|
|
type PageBlocksEventType =
|
|
|
|
| "PAGE_BLOCK_CREATE"
|
|
|
|
| "PAGE_BLOCK_UPDATE"
|
|
|
|
| "PAGE_BLOCK_DELETE"
|
|
|
|
| "PAGE_BLOCK_CONVERTED_TO_ISSUE";
|
|
|
|
|
|
|
|
type GptEventType = "ASK_GPT" | "USE_GPT_RESPONSE_IN_ISSUE" | "USE_GPT_RESPONSE_IN_PAGE_BLOCK";
|
|
|
|
|
|
|
|
class TrackEventServices extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super("/");
|
2023-03-29 06:54:19 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackWorkspaceEvent(data: IWorkspace | any, eventName: WorkspaceEventType): Promise<any> {
|
|
|
|
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-03-30 13:57:46 +00:00
|
|
|
async trackProjectEvent(
|
|
|
|
data: Partial<IProject> | any,
|
|
|
|
eventName: ProjectEventType
|
|
|
|
): Promise<any> {
|
|
|
|
let payload: any;
|
|
|
|
if (eventName !== "DELETE_PROJECT")
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async trackUserOnboardingCompleteEvent(data: any): Promise<any> {
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: "USER_ONBOARDING_COMPLETE",
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackIssueEvent(data: IIssue | any, eventName: IssueEventType): Promise<any> {
|
|
|
|
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,
|
|
|
|
issueTitle: 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-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async trackIssueBulkDeleteEvent(data: any): Promise<any> {
|
|
|
|
return this.request({
|
|
|
|
url: "/api/track-event",
|
|
|
|
method: "POST",
|
|
|
|
data: {
|
|
|
|
eventName: "ISSUE_BULK_DELETE",
|
|
|
|
extra: {
|
|
|
|
...data,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackStateEvent(data: IState | any, eventName: StateEventType): Promise<any> {
|
|
|
|
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,
|
|
|
|
stateName: 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-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackCycleEvent(data: ICycle | any, eventName: CycleEventType): Promise<any> {
|
|
|
|
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,
|
|
|
|
cycleName: 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-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackModuleEvent(data: IModule | any, eventName: ModuleEventType): Promise<any> {
|
|
|
|
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,
|
|
|
|
moduleName: 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-29 09:08:30 +00:00
|
|
|
...payload,
|
2023-03-29 06:54:19 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-30 13:57:46 +00:00
|
|
|
async trackPageEvent(data: Partial<IPage> | any, eventName: PagesEventType): Promise<any> {
|
|
|
|
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-03-30 13:57:46 +00:00
|
|
|
async trackPageBlockEvent(
|
|
|
|
data: Partial<IPageBlock> | IIssue,
|
|
|
|
eventName: PageBlocksEventType
|
|
|
|
): 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-03-30 13:57:46 +00:00
|
|
|
async trackAskGptEvent(data: IGptResponse, eventName: GptEventType): 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-03-30 13:57:46 +00:00
|
|
|
async trackUseGPTResponseEvent(data: IIssue | IPageBlock, eventName: GptEventType): Promise<any> {
|
|
|
|
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
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const trackEventServices = new TrackEventServices();
|
|
|
|
|
|
|
|
export default trackEventServices;
|