Install Mixpanel Swift via Carthage
masterTo use Carthage, add the following dependency to your Cartfile:
github "mixpanel/mixpanel-swift"github "mixpanel/mixpanel-swift"repository·master·Indexed 19 days ago
https://github.com/mixpanel/mixpanel-swiftAn open-source SDK for iOS applications to track user behavior, send event data, and manage user profiles. Supports installation via Swift Package Manager, CocoaPods, and Carthage.
To use Carthage, add the following dependency to your Cartfile:
github "mixpanel/mixpanel-swift"github "mixpanel/mixpanel-swift"To install using CocoaPods:
gem install cocoapods.pod setup to create a local spec mirror.pod init.pod 'Mixpanel-swift' to your Podfile.pod install in your project directory..xcworkspace file.pod 'Mixpanel-swift'The easiest way to integrate Mixpanel is using Swift Package Manager (available for v2.8.0+).
https://github.com/mixpanel/mixpanel-swift.Import Mixpanel and initialize it within your AppDelegate.swift inside the application(_:didFinishLaunchingWithOptions:) method. You will need your project token from your Mixpanel project settings.
Note: Setting trackAutomaticEvents to false prevents the SDK from automatically collecting common mobile events.
import Mixpanel
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
...
Mixpanel.initialize(token: "MIXPANEL_TOKEN", trackAutomaticEvents: false)
...
}optOutTracking() method. This sets the user's local opt-out state to true.Use Mixpanel.mainInstance().track(event:properties:) to send event data from anywhere in your application. You can include a dictionary of properties to provide additional context for the event.
Mixpanel.mainInstance().track(event: "Sign Up", properties: [
"source": "Pat's affiliate site",
"Opted out of email": true
])If events are not appearing in your Mixpanel dashboard, you can enable debug logging to see the library's output by setting loggingEnabled to true on the main instance.
Mixpanel.mainInstance().loggingEnabled = trueThe Mixpanel library batches events and sends them every 60 seconds or when the app moves to the background to preserve battery and bandwidth. If you need to ensure data is sent immediately, call flush() manually.
Mixpanel.mainInstance().flush()