update consent handling and remove unused error capture logic
This commit is contained in:
@@ -2,7 +2,8 @@ import { Preferences } from '@capacitor/preferences'
|
|||||||
|
|
||||||
// Two independent consent axes, matching the existing onboarding UI
|
// Two independent consent axes, matching the existing onboarding UI
|
||||||
// (HeardAboutView's PrivacyPreferences): "analytics" gates track(), "crash"
|
// (HeardAboutView's PrivacyPreferences): "analytics" gates track(), "crash"
|
||||||
// gates captureError(). A self-hosted user can opt into one without the other.
|
// gates captureException(). A self-hosted user can opt into one without the
|
||||||
|
// other.
|
||||||
const CONSENT_KEYS = {
|
const CONSENT_KEYS = {
|
||||||
analytics: 'analytics_consent',
|
analytics: 'analytics_consent',
|
||||||
crash: 'analytics_crash_consent',
|
crash: 'analytics_crash_consent',
|
||||||
|
|||||||
@@ -79,12 +79,6 @@ export const EVENT_SCHEMAS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ERROR_SCHEMAS = {
|
export const ERROR_SCHEMAS = {
|
||||||
api_error: {
|
|
||||||
http_status: 'string',
|
|
||||||
method: 'string',
|
|
||||||
error_code: 'string',
|
|
||||||
operation: 'string',
|
|
||||||
},
|
|
||||||
// No message/stack field here by design — those come from the real Error
|
// No message/stack field here by design — those come from the real Error
|
||||||
// object passed to posthog.captureException() itself, not from this
|
// object passed to posthog.captureException() itself, not from this
|
||||||
// sanitized properties bag. This schema only classifies how it was caught.
|
// sanitized properties bag. This schema only classifies how it was caught.
|
||||||
|
|||||||
@@ -142,20 +142,6 @@ export const track = (eventName, properties = {}) => {
|
|||||||
posthog.capture(eventName, sanitized)
|
posthog.capture(eventName, sanitized)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Backend/API failures: a normal sanitized event, same as track() — not
|
|
||||||
* PostHog's Error Tracking product. There's no real Error object here (just
|
|
||||||
* an HTTP response), so there's no stack trace to gain from captureException. */
|
|
||||||
export const captureError = (errorType, properties = {}) => {
|
|
||||||
if (!canSend('crash')) return
|
|
||||||
const posthog = getClientSync()
|
|
||||||
if (!posthog) return
|
|
||||||
|
|
||||||
const sanitized = sanitizeErrorProperties(errorType, properties)
|
|
||||||
if (!sanitized) return
|
|
||||||
|
|
||||||
posthog.capture(errorType, sanitized)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frontend crashes only. Uses captureException (not capture) so these land
|
* Frontend crashes only. Uses captureException (not capture) so these land
|
||||||
* on PostHog's Error Tracking page with a genuine message + stack trace —
|
* on PostHog's Error Tracking page with a genuine message + stack trace —
|
||||||
@@ -176,7 +162,7 @@ export const captureException = (error, properties = {}) => {
|
|||||||
let globalHandlersInstalled = false
|
let globalHandlersInstalled = false
|
||||||
|
|
||||||
/** Reports uncaught exceptions and unhandled promise rejections to
|
/** Reports uncaught exceptions and unhandled promise rejections to
|
||||||
* PostHog's Error Tracking, gated by the same crash consent as api_error.
|
* PostHog's Error Tracking, gated by crash consent.
|
||||||
* Complements, doesn't overlap with, src/views/Error.jsx: that's a React
|
* Complements, doesn't overlap with, src/views/Error.jsx: that's a React
|
||||||
* Router error-boundary screen for render/loader errors, which React catches
|
* Router error-boundary screen for render/loader errors, which React catches
|
||||||
* before they ever reach window.onerror — a different class of failure, with
|
* before they ever reach window.onerror — a different class of failure, with
|
||||||
@@ -206,7 +192,7 @@ export const installGlobalErrorHandlers = () => {
|
|||||||
/**
|
/**
|
||||||
* kind: 'analytics' | 'crash'. Enabling analytics (re-)initializes PostHog
|
* kind: 'analytics' | 'crash'. Enabling analytics (re-)initializes PostHog
|
||||||
* if needed and sends analytics_enabled; enabling crash-only never talks to
|
* if needed and sends analytics_enabled; enabling crash-only never talks to
|
||||||
* PostHog by itself (it only unlocks captureError once something reports).
|
* PostHog by itself (it only unlocks captureException once something crashes).
|
||||||
* Disabling never sends an event and clears identity/queued data.
|
* Disabling never sends an event and clears identity/queued data.
|
||||||
*/
|
*/
|
||||||
export const setConsent = async (kind, value, { source } = {}) => {
|
export const setConsent = async (kind, value, { source } = {}) => {
|
||||||
@@ -236,7 +222,7 @@ export const setConsent = async (kind, value, { source } = {}) => {
|
|||||||
} else if (kind === 'crash') {
|
} else if (kind === 'crash') {
|
||||||
// Crash reporting alone doesn't need PostHog started with the analytics
|
// Crash reporting alone doesn't need PostHog started with the analytics
|
||||||
// super-properties path, but it does need a live client + identity to
|
// super-properties path, but it does need a live client + identity to
|
||||||
// send captureError() calls through.
|
// send captureException() calls through.
|
||||||
if (isConfigured() && !getClientSync()) {
|
if (isConfigured() && !getClientSync()) {
|
||||||
await startPosthog()
|
await startPosthog()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { Preferences } from '@capacitor/preferences'
|
import { Preferences } from '@capacitor/preferences'
|
||||||
|
|
||||||
import { captureError } from '../analytics'
|
|
||||||
import { API_URL } from '../Config'
|
import { API_URL } from '../Config'
|
||||||
import { networkManager } from '../hooks/NetworkManager'
|
import { networkManager } from '../hooks/NetworkManager'
|
||||||
import {
|
import {
|
||||||
normalizeEndpoint,
|
|
||||||
recordApiFailure,
|
recordApiFailure,
|
||||||
recordServerVersionFromResponse,
|
recordServerVersionFromResponse,
|
||||||
} from '../service/DiagnosticsSession'
|
} from '../service/DiagnosticsSession'
|
||||||
@@ -230,11 +228,6 @@ class ApiClient {
|
|||||||
method: config.method,
|
method: config.method,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
})
|
})
|
||||||
captureError('api_error', {
|
|
||||||
http_status: String(response.status),
|
|
||||||
method: config.method || 'GET',
|
|
||||||
operation: normalizeEndpoint(endpoint),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Check for 401 (Unauthorized)
|
// 2. Check for 401 (Unauthorized)
|
||||||
@@ -319,11 +312,6 @@ class ApiClient {
|
|||||||
if (!externalAbort) {
|
if (!externalAbort) {
|
||||||
networkManager.setServerUnreachable()
|
networkManager.setServerUnreachable()
|
||||||
recordApiFailure({ endpoint, method: config.method, status: 'network' })
|
recordApiFailure({ endpoint, method: config.method, status: 'network' })
|
||||||
captureError('api_error', {
|
|
||||||
http_status: 'network',
|
|
||||||
method: config.method || 'GET',
|
|
||||||
operation: normalizeEndpoint(endpoint),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
console.error('Request failed', error)
|
console.error('Request failed', error)
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
Reference in New Issue
Block a user