Files
self/app/ios/SelfAnalytics.swift
Justin Hernandez ba856226d8 SELF-1812: integrate sumsub into mobile app (#1650)
* sumsub initial pass

* add sumsub tee url

* agent feedback and fixes

* update lock

* agent feedback

* fix types

* agnet feedback

* fix mock

* agent feedback

* lazy load sumsub screen

* white button color

* fix lint

* add debug url link

* allow us to see recordings

* debug maestro run

* disable e2e screen recording for now. don't load sumsub logic when running e2e test

* remove lazy loading

* skip installing sumsub plugin

* retest ios e2e

* get e2e tests passing

* clean up
2026-01-26 14:06:36 -08:00

82 lines
3.0 KiB
Swift

// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11
import Foundation
import Mixpanel
#if !E2E_TESTING
import NFCPassportReader
public class SelfAnalytics: Analytics {
private let enableDebugLogs: Bool
public override init(token: String, enableDebugLogs: Bool = false, trackAutomaticEvents: Bool = false) {
self.enableDebugLogs = enableDebugLogs
super.init(token: token, enableDebugLogs: enableDebugLogs, trackAutomaticEvents: trackAutomaticEvents)
}
public override func trackEvent(_ name: String, properties: Properties? = nil) {
super.trackEvent(name, properties: properties)
print("[NFC Analytics] Event: \(name), Properties: \(properties ?? [:])")
if let logger = NativeLoggerBridge.shared {
logger.sendEvent(withName: "logEvent", body: [
"level": "info",
"category": "NFC",
"message": "Analytics Event: \(name)",
"data": properties ?? [:]
])
}
}
public override func trackDebugEvent(_ name: String, properties: Properties? = nil) {
super.trackDebugEvent(name, properties: properties)
if enableDebugLogs {
print("[NFC Analytics Debug] Event: \(name), Properties: \(properties ?? [:])")
if let logger = NativeLoggerBridge.shared {
logger.sendEvent(withName: "logEvent", body: [
"level": "debug",
"category": "NFC",
"message": "Analytics Debug Event: \(name)",
"data": properties ?? [:]
])
}
}
}
public override func trackError(_ error: Error, context: String) {
super.trackError(error, context: context)
print("[NFC Analytics Error] Context: \(context), Error: \(error.localizedDescription)")
if let logger = NativeLoggerBridge.shared {
logger.sendEvent(withName: "logEvent", body: [
"level": "error",
"category": "NFC",
"message": "Analytics Error: \(error.localizedDescription)",
"data": [
"error_type": String(describing: type(of: error)),
"error_description": error.localizedDescription,
"context": context
]
])
}
}
public func flush() {
Mixpanel.mainInstance().flush()
}
}
#else
// E2E Testing stub - SelfAnalytics is not used when NFCPassportReader is excluded
public class SelfAnalytics {
public init(token: String, enableDebugLogs: Bool = false, trackAutomaticEvents: Bool = false) {}
public func trackEvent(_ name: String, properties: [String: Any]? = nil) {}
public func trackDebugEvent(_ name: String, properties: [String: Any]? = nil) {}
public func trackError(_ error: Error, context: String) {}
public func flush() {}
}
#endif