Swiftpack.co - Package - mixpanel/mixpanel-swift

Mixpanel Swift Library

Build Status Average time to resolve an issue Percentage of issues still open CocoaPods Compatible Carthage compatible Apache License Documentation

Table of Contents


Welcome to the official Mixpanel Swift Library

The Mixpanel Swift library for iOS is an open source project, and we'd love to see your contributions! We'd also love for you to come and work with us! Check out Jobs for details.

If you are using Objective-C, we recommend using our Objective-C Library.

Current supported features

Our master branch and our releases are now on Swift 5.

If you wish to use our Swift 4.2 implementation, please point to the v2.6.1 release. For Swift 4/4.1 implementation, please point to the v2.4.5 release. For Swift 3 implementation, please point to the v2.2.3 release. For Swift 2.3 implementation, please point to the v1.0.1 release.

Our Swift library fully supports all of the Mixpanel features, and has full parity with the Objective-C Library.



Our current release only supports CocoaPods version 1.4.0+

Mixpanel supports CocoaPods for easy installation. To Install, see our swift integration guide »

For iOS, tvOS, macOS, and App Extension integrations:

pod 'Mixpanel-swift'


Mixpanel also supports Carthage to package your dependencies as a framework. Include the following dependency in your Cartfile:

github "mixpanel/mixpanel-swift"

Check out the Carthage docs » for more info.

Manual Installation

To help users stay up to date with the latests version of our Swift SDK, we always recommend integrating our SDK via CocoaPods, which simplifies version updates and dependency management. However, there are cases where users can't use CocoaPods. Not to worry, just follow these manual installation steps and you'll be all set.

Step 1: Add as a Submodule

Add Mixpanel as a submodule to your local git repo like so:

git submodule add git@github.com:mixpanel/mixpanel-swift.git

Now the Mixpanel project and its files should be in your project folder!

Step 2: Drag Mixpanel to your project

Drag the Mixpanel.xcodeproj inside your sample project under the main sample project file:

alt text

Step 3: Embed the framework

Select your app .xcodeproj file. Under "General", add the Mixpanel framework as an embedded binary:

alt text

Initializing and Usage


Import Mixpanel into AppDelegate.swift, and initialize Mixpanel within application:didFinishLaunchingWithOptions: alt text

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    Mixpanel.initialize(token: "MIXPANEL_TOKEN")

You initialize your Mixpanel instance with the token provided to you on mixpanel.com.

Start tracking

After installing the library into your iOS app, Mixpanel will automatically collect common mobile events. You can enable/ disable automatic collection through your project settings.

To interact with the instance and track additional events, you can either use the mixpanel instance given when initializing:

mixpanel.track(event: "Tracked Event!")

or you can directly fetch the instance and use it from the Mixpanel object:

Mixpanel.mainInstance().track(event: "Tracked Event!")

You're done! You've successfully integrated the Mixpanel Swift SDK into your app. To stay up to speed on important SDK releases and updates, star or watch our repository on Github.

Have any questions? Reach out to support@mixpanel.com to speak to someone smart, quickly.


Stars: 231
Help us keep the lights on


Used By

Total: 0


v2.6.5 - Aug 23, 2019

Fix duplicate triggered inapps shown between app sessions https://github.com/mixpanel/mixpanel-swift/pull/324

v2.6.4 - Aug 19, 2019

PR: https://github.com/mixpanel/mixpanel-swift/pull/322

  • Crash with Set.contains(_:) https://github.com/mixpanel/mixpanel-swift/issues/321
  • MixpanelInstance.checkDecide crash https://github.com/mixpanel/mixpanel-swift/issues/312
  • Crash in Persistence https://github.com/mixpanel/mixpanel-swift/issues/310
  • Bad Access in Global Lock https://github.com/mixpanel/mixpanel-swift/issues/309

PR: https://github.com/mixpanel/mixpanel-swift/pull/317 Thanks @RamblinWreck77 !

  • Crash in Network.swift https://github.com/mixpanel/mixpanel-swift/issues/314

PR: https://github.com/mixpanel/mixpanel-swift/pull/305

  • A/B Developer tweaks won't update https://github.com/mixpanel/mixpanel-swift/issues/302

v2.6.3 - Jun 7, 2019

mixpanel.identify() now sends a special $identify event to the API. This is not treated like a regular tracking event, but will aid in future platform improvements to support advanced identity management (linking anonymous and logged-in usage, multiple users on one system, etc.).

if more than one user can be identified in your app (ie log-out/log-in scenarios) make sure you call reset() when a user logs-out and that you add MIXPANEL_RANDOM_DISTINCT_ID Active Complilation Conditions in your build settings so anonymous users don't have the same distinct_id (IFA/IFV by default) https://github.com/mixpanel/mixpanel-swift/pull/306

fix a potential crash issue by fetching the current super properties https://github.com/mixpanel/mixpanel-swift/pull/304

fix deadlock in readwrite lock https://github.com/mixpanel/mixpanel-swift/pull/307 thanks @RamblinWreck77

Missing case in makeObjectSerializable() : NaN or infinity cannot be serialized as JSON https://github.com/mixpanel/mixpanel-swift/pull/303 thanks @tonysung

Prefix swizzled method name https://github.com/mixpanel/mixpanel-swift/pull/289 thanks @ChrisGriffiths

v2.6.2 - Apr 1, 2019

  • Xcode 10.2 and swift 5 support https://github.com/mixpanel/mixpanel-swift/pull/296

v2.6.1 - Mar 28, 2019

  • Include super properties during display trigger evaluation
  • Fix bug while comparing string types https://github.com/mixpanel/mixpanel-swift/pull/291