Migrate Analytics (#951)

* setup analytics adapter for self mobile sdk client and use in app

* wrap for context

* fix build

* yarn types is an alias for build when build just compiles ts

* ok unlock

* deeper

* ok this looks to work

* fix license check

* make sure it starts with this line

* someone didnt commit

* fix double analytics bug and builds

* lint
This commit is contained in:
Aaron DeRuvo
2025-08-26 15:40:14 +02:00
committed by GitHub
parent cf75bfa0ba
commit 4367780cd6
48 changed files with 221 additions and 157 deletions

View File

@@ -4,45 +4,10 @@
import type { JsonMap, JsonValue } from '@segment/analytics-react-native';
import { TrackEventParams } from '@selfxyz/mobile-sdk-alpha';
import { createSegmentClient } from '@/Segment';
/**
* Generic reasons:
* - network_error: Network connectivity issues
* - user_cancelled: User cancelled the operation
* - permission_denied: Permission not granted
* - invalid_input: Invalid user input
* - timeout: Operation timed out
* - unknown_error: Unspecified error
*
* Auth specific:
* - invalid_credentials: Invalid login credentials
* - biometric_unavailable: Biometric authentication unavailable
* - invalid_mnemonic: Invalid mnemonic phrase
*
* Passport specific:
* - invalid_format: Invalid passport format
* - expired_passport: Passport is expired
* - scan_error: Error during scanning
* - nfc_error: NFC read error
*
* Proof specific:
* - verification_failed: Proof verification failed
* - session_expired: Session expired
* - missing_fields: Required fields missing
*
* Backup specific:
* - backup_not_found: Backup not found
* - cloud_service_unavailable: Cloud service unavailable
*/
export interface EventParams {
reason?: string | null;
duration_seconds?: number;
attempt_count?: number;
[key: string]: unknown;
}
const segmentClient = createSegmentClient();
function coerceToJsonValue(
@@ -102,7 +67,7 @@ function validateParams(
): JsonMap | undefined {
if (!properties) return undefined;
const validatedProps = { ...properties } as EventParams;
const validatedProps = { ...properties };
// Ensure duration is formatted as a number with at most 2 decimal places
if (validatedProps.duration_seconds !== undefined) {
@@ -153,7 +118,7 @@ const analytics = () => {
return {
// Using LiteralCheck will allow constants but not plain string literals
trackEvent: (eventName: string, properties?: EventParams) => {
trackEvent: (eventName: string, properties?: TrackEventParams) => {
_track('event', eventName, properties);
},
trackScreenView: (

View File

@@ -25,8 +25,11 @@ import {
getPayload,
getWSDbRelayerUrl,
} from '@selfxyz/common/utils/proving';
import {
PassportEvents,
ProofEvents,
} from '@selfxyz/mobile-sdk-alpha/constants/analytics';
import { PassportEvents, ProofEvents } from '@/consts/analytics';
import { navigationRef } from '@/navigation';
import { unsafe_getPrivateKey } from '@/providers/authProvider';
import {

View File

@@ -24,8 +24,8 @@ import {
import { getLeafDscTree } from '@selfxyz/common/utils/trees';
import type { PassportValidationCallbacks } from '@selfxyz/mobile-sdk-alpha';
import { isPassportDataValid } from '@selfxyz/mobile-sdk-alpha';
import { DocumentEvents } from '@selfxyz/mobile-sdk-alpha/constants/analytics';
import { DocumentEvents } from '@/consts/analytics';
import {
getAllDocuments,
loadDocumentCatalog,