// // AnalyticsManager.swift // 1Flow (https://1flow.app?ref=analytics_manager) // // Created by 1Flow on 29/09/22. // // import analytics libraries import Foundation import UIKit import Firebase import Mixpanel import _1Flow class AnalyticsManager { // set SDK tokens and keys static let oneFlowToken = "example_1flow_token" static let mixPanelToken = "example_mixpanel_token" // configure and initialize all SDKs class func configure() { // Firebase FirebaseApp.configure() // Mixpanel Mixpanel.initialize(token: mixPanelToken, trackAutomaticEvents: true) // 1Flow OneFlow.configure(oneFlowToken) } // to track event with properties class func track(_ event: String, properties: [String:Any]?) { print("[DEBUG] track(", event, ", properties: ", properties ?? [], ")") // Firebase Analytics.logEvent(event, parameters: properties) // Mixpanel Mixpanel.mainInstance().track(event: event, properties: properties as? Properties) // 1Flow OneFlow.recordEventName(event, parameters: properties) } // to identify user across analytics with traits. // recommended: you should call identify() on every new session. class func identify(_ userId: String, traits: [String:String]) { print("[DEBUG] identify(", userId, ", traits: ", traits, ")") // Firebase Analytics.setUserID(userId) for (key, value) in traits { Analytics.setUserProperty(value, forName: key) } // Mixpanel Mixpanel.mainInstance().identify(distinctId: userId) Mixpanel.mainInstance().people.set(properties: traits) // 1Flow OneFlow.logUser(userId, userDetails: traits) } // returns the userId string for the current user // TODO: fetch userId from your database and // use the same userId across all SDKs. class func getUserId() -> String? { // in this example below, we're using Firebase userID if Auth.auth().currentUser != nil { // signed in // Example: return Firebase ID return Auth.auth().currentUser?.uid as? String } else { // not signed in // Example: return deviceID string to use as userId return UIDevice.current.identifierForVendor?.uuidString } } }