This is optional - we recommend it as a best practice if you haven’t adopted a similar architecture already.
You can track events and update user traits to all the SDKs you use with this simple analytics manager class, so you won’t ever need to worry about needing more engineering work to track new events in the future.
Below we’re providing an example implementation of a custom analytics manager class you can adopt to send analytics data to 1Flow as well as all other SDKs you use. This will save you time and make your event tracking on autopilot going forward.
The below example is written in iOS-Swift but you / your developer can easily adopt this structure for any language.
swift// // 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 } } }
The source file is available for download here: