Add PostHog analytics events matching iOS/KMM event names
- Define AnalyticsEvents constants matching iOS AnalyticsEvent enum - Track user_signed_in, user_registered with identify/reset - Track residence_created, task_created, contractor_created, document_created - Track residence_shared, theme_changed - All events include platform:'web' for cross-platform filtering - Reset PostHog on logout Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -45,3 +45,38 @@ export function resetAnalytics() {
|
||||
posthog.reset();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Event names — match iOS/KMM AnalyticsEvents for cross-platform consistency
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const AnalyticsEvents = {
|
||||
// Auth
|
||||
USER_REGISTERED: "user_registered",
|
||||
USER_SIGNED_IN: "user_signed_in",
|
||||
|
||||
// Residences
|
||||
RESIDENCE_CREATED: "residence_created",
|
||||
RESIDENCE_LIMIT_REACHED: "residence_limit_reached",
|
||||
RESIDENCE_SHARED: "residence_shared",
|
||||
|
||||
// Tasks
|
||||
TASK_CREATED: "task_created",
|
||||
|
||||
// Contractors
|
||||
CONTRACTOR_CREATED: "contractor_created",
|
||||
CONTRACTOR_PAYWALL_SHOWN: "contractor_paywall_shown",
|
||||
|
||||
// Documents
|
||||
DOCUMENT_CREATED: "document_created",
|
||||
DOCUMENTS_PAYWALL_SHOWN: "documents_paywall_shown",
|
||||
|
||||
// Sharing
|
||||
SHARE_RESIDENCE_PAYWALL_SHOWN: "share_residence_paywall_shown",
|
||||
|
||||
// Settings
|
||||
THEME_CHANGED: "theme_changed",
|
||||
|
||||
// Errors
|
||||
ERROR_OCCURRED: "error_occurred",
|
||||
} as const;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
|
||||
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
|
||||
import type { CreateContractorRequest, UpdateContractorRequest } from '@/lib/api/contractors';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -51,6 +52,7 @@ export function useCreateContractor() {
|
||||
mutationFn: (data: CreateContractorRequest) =>
|
||||
contractors.create(data),
|
||||
onSuccess: () => {
|
||||
trackEvent(AnalyticsEvents.CONTRACTOR_CREATED, { platform: 'web' });
|
||||
queryClient.invalidateQueries({ queryKey: qk('contractors') });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
|
||||
import type { DocumentListParams, CreateDocumentRequest, UpdateDocumentRequest } from '@/lib/api/documents';
|
||||
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
|
||||
import type { DocumentListParams, CreateDocumentRequest, UpdateDocumentRequest, DocumentResponse } from '@/lib/api/documents';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Query hooks
|
||||
@@ -49,7 +50,11 @@ export function useCreateDocument() {
|
||||
}
|
||||
return documents.create(data);
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSuccess: (result: DocumentResponse) => {
|
||||
trackEvent(AnalyticsEvents.DOCUMENT_CREATED, {
|
||||
type: result.document_type,
|
||||
platform: 'web',
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: qk('documents') });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
|
||||
import type { CreateResidenceRequest, UpdateResidenceRequest } from '@/lib/api/residences';
|
||||
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
|
||||
import type { CreateResidenceRequest, UpdateResidenceRequest, ResidenceResponse } from '@/lib/api/residences';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Query hooks
|
||||
@@ -39,7 +40,11 @@ export function useCreateResidence() {
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateResidenceRequest) =>
|
||||
residences.create(data),
|
||||
onSuccess: () => {
|
||||
onSuccess: (result: ResidenceResponse) => {
|
||||
trackEvent(AnalyticsEvents.RESIDENCE_CREATED, {
|
||||
residence_type: result.property_type?.name,
|
||||
platform: 'web',
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: qk('residences') });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
|
||||
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Query hooks
|
||||
@@ -38,6 +39,7 @@ export function useGenerateShareCode(residenceId: number) {
|
||||
return useMutation({
|
||||
mutationFn: () => sharing.generateShareCode(residenceId),
|
||||
onSuccess: () => {
|
||||
trackEvent(AnalyticsEvents.RESIDENCE_SHARED, { method: 'code', platform: 'web' });
|
||||
queryClient.invalidateQueries({ queryKey: qk('residences', residenceId, 'share-code') });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useDataProvider, useQueryKeyPrefix } from '@/lib/demo/data-provider-context';
|
||||
import type { CreateTaskRequest, UpdateTaskRequest, CreateCompletionRequest } from '@/lib/api/tasks';
|
||||
import { trackEvent, AnalyticsEvents } from '@/lib/analytics';
|
||||
import type { CreateTaskRequest, UpdateTaskRequest, CreateCompletionRequest, TaskResponse } from '@/lib/api/tasks';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Query hooks
|
||||
@@ -67,7 +68,11 @@ export function useCreateTask() {
|
||||
const qk = useQueryKeyPrefix();
|
||||
return useMutation({
|
||||
mutationFn: (data: CreateTaskRequest) => tasks.create(data),
|
||||
onSuccess: () => {
|
||||
onSuccess: (result: TaskResponse) => {
|
||||
trackEvent(AnalyticsEvents.TASK_CREATED, {
|
||||
residence_id: result.residence_id,
|
||||
platform: 'web',
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: qk('tasks') });
|
||||
queryClient.invalidateQueries({ queryKey: qk('residences') });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user