Unofficial Mixpanel client written in Swift 4.2 for iOS and Mac.
This is a very simple client that just implements tracking events and identifying the current user. A network request is initiated whenver you call track
. If it fails, nothing happens. Eventually, it would be cool if it stored these and retried at some point.
Carthage is the recommended way to install Mixpanel. Add the following to your Cartfile:
github "soffes/Mixpanel"
import Mixpanel
// Setup a client
let mixpanel = Mixpanel(token: "your app token")
// Identify the current user. This doesn't make a network request. It simply
// will add their identifer to the next event tracked.
mixpanel.identify("7")
// Track an event
mixpanel.track("Launch")
// Track an event with parameters
mixpanel.track("Share", parameters: [
"service": "Twitter",
])
// You can also customize the time the event happened and add a completion
// handler if you want.
mixpanel.track("Import photo", parameters: [
"source": "Photo library"
], time: someTime, completion: (success) in {
println("Tracked event successfully: \(success)")
})
Enjoy.