mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-07 23:02:39 +02:00
feat: added posthog
This commit is contained in:
parent
80e4f1b798
commit
c96be7d9e1
18 changed files with 506 additions and 19 deletions
|
|
@ -8,6 +8,7 @@ import type {
|
|||
UpdateDocumentRequest,
|
||||
UploadDocumentRequest,
|
||||
} from "@/contracts/types/document.types";
|
||||
import { trackDocumentDeleted, trackDocumentIndexed } from "@/lib/analytics";
|
||||
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -24,7 +25,15 @@ export const createDocumentMutationAtom = atomWithMutation((get) => {
|
|||
return documentsApiService.createDocument(request);
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
onSuccess: (data, request: CreateDocumentRequest) => {
|
||||
// Track document creation/indexing
|
||||
if (searchSpaceId) {
|
||||
trackDocumentIndexed({
|
||||
search_space_id: Number(searchSpaceId),
|
||||
document_type: request.document_type,
|
||||
});
|
||||
}
|
||||
|
||||
toast.success("Document created successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.documents.globalQueryParams(documentsQueryParams),
|
||||
|
|
@ -91,6 +100,14 @@ export const deleteDocumentMutationAtom = atomWithMutation((get) => {
|
|||
},
|
||||
|
||||
onSuccess: (_, request: DeleteDocumentRequest) => {
|
||||
// Track document deletion
|
||||
if (searchSpaceId) {
|
||||
trackDocumentDeleted({
|
||||
search_space_id: Number(searchSpaceId),
|
||||
document_id: request.id,
|
||||
});
|
||||
}
|
||||
|
||||
toast.success("Document deleted successfully");
|
||||
queryClient.setQueryData(
|
||||
cacheKeys.documents.globalQueryParams(documentsQueryParams),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import type {
|
|||
DeleteInviteRequest,
|
||||
UpdateInviteRequest,
|
||||
} from "@/contracts/types/invites.types";
|
||||
import { trackInviteAccepted, trackInviteCreated } from "@/lib/analytics";
|
||||
import { invitesApiService } from "@/lib/apis/invites-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -18,6 +19,12 @@ export const createInviteMutationAtom = atomWithMutation(() => ({
|
|||
return invitesApiService.createInvite(request);
|
||||
},
|
||||
onSuccess: (_, variables) => {
|
||||
// Track invite creation
|
||||
trackInviteCreated({
|
||||
search_space_id: variables.search_space_id,
|
||||
role_name: variables.data.role_id ? `role_${variables.data.role_id}` : undefined,
|
||||
});
|
||||
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.invites.all(variables.search_space_id.toString()),
|
||||
});
|
||||
|
|
@ -74,7 +81,13 @@ export const acceptInviteMutationAtom = atomWithMutation(() => ({
|
|||
mutationFn: async (request: AcceptInviteRequest) => {
|
||||
return invitesApiService.acceptInvite(request);
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: (data, variables) => {
|
||||
// Track invite acceptance
|
||||
trackInviteAccepted({
|
||||
search_space_id: data.search_space_id,
|
||||
invite_code: variables.invite_code,
|
||||
});
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: cacheKeys.searchSpaces.all });
|
||||
toast.success("Invite accepted successfully");
|
||||
},
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import type {
|
|||
UpdateNewLLMConfigRequest,
|
||||
UpdateNewLLMConfigResponse,
|
||||
} from "@/contracts/types/new-llm-config.types";
|
||||
import { trackLLMConfigCreated } from "@/lib/analytics";
|
||||
import { newLLMConfigApiService } from "@/lib/apis/new-llm-config-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -25,7 +26,16 @@ export const createNewLLMConfigMutationAtom = atomWithMutation((get) => {
|
|||
mutationFn: async (request: CreateNewLLMConfigRequest) => {
|
||||
return newLLMConfigApiService.createConfig(request);
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: (_, request: CreateNewLLMConfigRequest) => {
|
||||
// Track LLM config creation
|
||||
if (searchSpaceId) {
|
||||
trackLLMConfigCreated({
|
||||
search_space_id: Number(searchSpaceId),
|
||||
provider: request.provider,
|
||||
model_name: request.model_name,
|
||||
});
|
||||
}
|
||||
|
||||
toast.success("Configuration created successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.newLLMConfigs.all(Number(searchSpaceId)),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import type {
|
|||
DeleteSearchSpaceRequest,
|
||||
UpdateSearchSpaceRequest,
|
||||
} from "@/contracts/types/search-space.types";
|
||||
import { trackSearchSpaceCreated, trackSearchSpaceDeleted } from "@/lib/analytics";
|
||||
import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service";
|
||||
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||
import { queryClient } from "@/lib/query-client/client";
|
||||
|
|
@ -17,7 +18,10 @@ export const createSearchSpaceMutationAtom = atomWithMutation(() => {
|
|||
return searchSpacesApiService.createSearchSpace(request);
|
||||
},
|
||||
|
||||
onSuccess: () => {
|
||||
onSuccess: (data, request: CreateSearchSpaceRequest) => {
|
||||
// Track search space creation
|
||||
trackSearchSpaceCreated({ search_space_id: data.id, name: request.name });
|
||||
|
||||
toast.success("Search space created successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.all,
|
||||
|
|
@ -61,6 +65,11 @@ export const deleteSearchSpaceMutationAtom = atomWithMutation((get) => {
|
|||
},
|
||||
|
||||
onSuccess: (_, request: DeleteSearchSpaceRequest) => {
|
||||
// Track search space deletion
|
||||
if (request.id) {
|
||||
trackSearchSpaceDeleted({ search_space_id: request.id });
|
||||
}
|
||||
|
||||
toast.success("Search space deleted successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: cacheKeys.searchSpaces.all,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue