fix: transmitting selective data for analytics (#578)

This commit is contained in:
Dakshesh Jain 2023-03-29 14:38:30 +05:30 committed by GitHub
parent 2138ddf1f5
commit 06daf68753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 176 additions and 32 deletions

View File

@ -38,7 +38,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
jitsu jitsu
.id({ .id({
...user, id: user.id,
email: user.email,
first_name: user.first_name,
last_name: user.last_name,
}) })
.then(() => { .then(() => {
jitsu.track(eventName, { jitsu.track(eventName, {

View File

@ -1,7 +1,7 @@
// services // services
import APIService from "services/api.service"; import APIService from "services/api.service";
// types // 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 // TODO: as we add more events, we can refactor this to be divided into different classes
class TrackEventServices extends APIService { class TrackEventServices extends APIService {
@ -10,26 +10,36 @@ class TrackEventServices extends APIService {
} }
async trackCreateWorkspaceEvent(data: IWorkspace): Promise<any> { async trackCreateWorkspaceEvent(data: IWorkspace): Promise<any> {
const payload = {
workspaceId: data.id,
workspaceSlug: data.slug,
workspaceName: data.name,
};
return this.request({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "CREATE_WORKSPACE", eventName: "CREATE_WORKSPACE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackUpdateWorkspaceEvent(data: IWorkspace): Promise<any> { async trackUpdateWorkspaceEvent(data: Partial<IWorkspace>): Promise<any> {
const payload = {
workspaceId: data.id,
workspaceSlug: data.slug,
workspaceName: data.name,
};
return this.request({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "UPDATE_WORKSPACE", eventName: "UPDATE_WORKSPACE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
@ -48,27 +58,41 @@ class TrackEventServices extends APIService {
}); });
} }
async trackCreateProjectEvent(data: any): Promise<any> { async trackCreateProjectEvent(data: IProject): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "CREATE_PROJECT", eventName: "CREATE_PROJECT",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackUpdateProjectEvent(data: any): Promise<any> { async trackUpdateProjectEvent(data: Partial<IProject>): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "UPDATE_PROJECT", eventName: "UPDATE_PROJECT",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
@ -139,27 +163,47 @@ class TrackEventServices extends APIService {
}); });
} }
async trackIssueCreateEvent(data: any): Promise<any> { async trackIssueCreateEvent(data: IIssue): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "ISSUE_CREATE", eventName: "ISSUE_CREATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackIssueUpdateEvent(data: any): Promise<any> { async trackIssueUpdateEvent(data: Partial<IIssue>): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "ISSUE_UPDATE", eventName: "ISSUE_UPDATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
@ -191,27 +235,47 @@ class TrackEventServices extends APIService {
}); });
} }
async trackStateCreateEvent(data: any): Promise<any> { async trackStateCreateEvent(data: IState): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "STATE_CREATE", eventName: "STATE_CREATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackStateUpdateEvent(data: any): Promise<any> { async trackStateUpdateEvent(data: Partial<IState>): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "STATE_UPDATE", eventName: "STATE_UPDATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
@ -230,27 +294,47 @@ class TrackEventServices extends APIService {
}); });
} }
async trackCycleCreateEvent(data: any): Promise<any> { async trackCycleCreateEvent(data: ICycle): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "CYCLE_CREATE", eventName: "CYCLE_CREATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackCycleUpdateEvent(data: any): Promise<any> { async trackCycleUpdateEvent(data: Partial<ICycle>): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "CYCLE_UPDATE", eventName: "CYCLE_UPDATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
@ -269,27 +353,45 @@ class TrackEventServices extends APIService {
}); });
} }
async trackModuleCreateEvent(data: any): Promise<any> { async trackModuleCreateEvent(data: IModule): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "MODULE_CREATE", eventName: "MODULE_CREATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });
} }
async trackModuleUpdateEvent(data: any): Promise<any> { async trackModuleUpdateEvent(data: Partial<IModule>): Promise<any> {
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({ return this.request({
url: "/api/track-event", url: "/api/track-event",
method: "POST", method: "POST",
data: { data: {
eventName: "MODULE_UPDATE", eventName: "MODULE_UPDATE",
extra: { extra: {
...data, ...payload,
}, },
}, },
}); });

View File

@ -1,4 +1,4 @@
import type { IUser, IIssue } from "."; import type { IUser, IIssue, IProject, IProjectLite, IWorkspace, IWorkspaceLite } from "types";
export interface ICycle { export interface ICycle {
backlog_issues: number; backlog_issues: number;
@ -14,6 +14,7 @@ export interface ICycle {
name: string; name: string;
owned_by: IUser; owned_by: IUser;
project: string; project: string;
project_detail: IProjectLite;
start_date: string | null; start_date: string | null;
started_issues: number; started_issues: number;
total_issues: number; total_issues: number;
@ -21,6 +22,7 @@ export interface ICycle {
updated_at: Date; updated_at: Date;
updated_by: string; updated_by: string;
workspace: string; workspace: string;
workspace_detail: IWorkspaceLite;
} }
export interface CurrentAndUpcomingCyclesResponse { export interface CurrentAndUpcomingCyclesResponse {

View File

@ -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 { export interface IIssueCycle {
id: string; id: string;
@ -96,7 +105,7 @@ export interface IIssue {
parent_detail: IIssueParent | null; parent_detail: IIssueParent | null;
priority: string | null; priority: string | null;
project: string; project: string;
project_detail: IProject; project_detail: IProjectLite;
sequence_id: number; sequence_id: number;
sort_order: number; sort_order: number;
sprints: string | null; sprints: string | null;
@ -108,6 +117,7 @@ export interface IIssue {
updated_at: Date; updated_at: Date;
updated_by: string; updated_by: string;
workspace: string; workspace: string;
workspace_detail: IWorkspaceLite;
labels: any[]; labels: any[];
labels_list: string[]; labels_list: string[];
} }

View File

@ -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 { export interface IModule {
backlog_issues: number; backlog_issues: number;
@ -28,7 +36,7 @@ export interface IModule {
is_favorite: boolean; is_favorite: boolean;
name: string; name: string;
project: string; project: string;
project_detail: IProject; project_detail: IProjectLite;
start_date: string | null; start_date: string | null;
started_issues: number; started_issues: number;
status: "backlog" | "planned" | "in-progress" | "paused" | "completed" | "cancelled" | null; status: "backlog" | "planned" | "in-progress" | "paused" | "completed" | "cancelled" | null;
@ -38,6 +46,7 @@ export interface IModule {
updated_at: Date; updated_at: Date;
updated_by: string; updated_by: string;
workspace: string; workspace: string;
workspace_detail: IWorkspaceLite;
} }
export interface ModuleIssueResponse { export interface ModuleIssueResponse {

View File

@ -2,9 +2,10 @@ import type {
IIssueFilterOptions, IIssueFilterOptions,
IUserLite, IUserLite,
IWorkspace, IWorkspace,
IWorkspaceLite,
TIssueGroupByOptions, TIssueGroupByOptions,
TIssueOrderByOptions, TIssueOrderByOptions,
} from "./"; } from "types";
export interface IProject { export interface IProject {
cover_image: string | null; cover_image: string | null;
@ -26,6 +27,13 @@ export interface IProject {
updated_at: Date; updated_at: Date;
updated_by: string; updated_by: string;
workspace: IWorkspace | string; workspace: IWorkspace | string;
workspace_detail: IWorkspaceLite;
}
export interface IProjectLite {
id: string;
name: string;
identifier: string;
} }
export interface IFavoriteProject { export interface IFavoriteProject {

View File

@ -1,3 +1,5 @@
import { IProject, IProjectLite, IWorkspaceLite } from "types";
export interface IState { export interface IState {
readonly id: string; readonly id: string;
color: string; color: string;
@ -8,11 +10,13 @@ export interface IState {
group: "backlog" | "unstarted" | "started" | "completed" | "cancelled"; group: "backlog" | "unstarted" | "started" | "completed" | "cancelled";
name: string; name: string;
project: string; project: string;
readonly project_detail: IProjectLite;
sequence: number; sequence: number;
readonly slug: string; readonly slug: string;
readonly updated_at: Date; readonly updated_at: Date;
readonly updated_by: string; readonly updated_by: string;
workspace: string; workspace: string;
workspace_detail: IWorkspaceLite;
} }
export interface StateResponse { export interface StateResponse {

View File

@ -1,4 +1,4 @@
import type { IProjectMember, IUser, IUserLite } from "./"; import type { IProjectMember, IUser, IUserLite } from "types";
export interface IWorkspace { export interface IWorkspace {
readonly id: string; readonly id: string;
@ -16,6 +16,12 @@ export interface IWorkspace {
company_size: number | null; company_size: number | null;
} }
export interface IWorkspaceLite {
readonly id: string;
name: string;
slug: string;
}
export interface IWorkspaceMemberInvitation { export interface IWorkspaceMemberInvitation {
readonly id: string; readonly id: string;
email: string; email: string;