Files
self/app/ios/SelfAnalytics.swift
Seshanth.S 577219e9c7 fix: didit ios native modules (#1867)
- Fixed openssl issue
- Fixed duplicate NFCPassportReader
- missing struct issue
2026-03-26 00:47:47 +05:30

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
#if !E2E_TESTING
import Mixpanel
import SelfNFCPassportReader
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