Mixpanel doesn’t always recommend tracking app open or app close Events, thus, Mixpanel doesn’t track them by default. What does Mixpanel recommend that I track instead?
However, if you’d like to track app open or app close Events, you can do so through the following Events:
App Open on iOS
For iOS, add an app open track call in two methods in your app delegate: didFinishLaunchingWithOptions and applicationWillEnterForeground.
If you have both an iOS and Android app and have chosen the default $app_open method for Android, make sure your iOS Event is also called $app_open so that you can compare the Event across libraries. Otherwise, naming them differently will result in two separate Events.
App Open on Android
- Use your own custom logic, which gives you complete control over when an app open is tracked. For example, you could use your own custom logic to track an app open event when a user quickly backgrounds and then re-opens your app. This requires understanding of the Android App Lifecycle and ActivityLifecycleCallbacks.
- Store the "status" of the app (whether or not any app activities are currently running) in a class that contains the ActivityLifecycleCallbacks - this class is referenced during the lifecycle methods of your activities.
- See a sample app that outlines this method.
- Alternatively, enable the Mixpanel default $app_open Event which will trigger on each singleton initialization of the Mixpanel instance. This occurs each time the user opens the app when the app is closed (including each new session of app use).
- If you have both an iOS and Android app and have chosen the default $app_open method for Android, note that the default $app_open event for Android will not be triggered when a user backgrounds the app and then quickly opens it again (because the library does not re-initialize). If you would like to capture an app open when a user performs this action (the equivalent of applicationWillEnterForeground in iOS), we recommend using your own custom logic to trigger an app open Event.
- To enable $app_open, add the following meta-data tag inside your tag in your Manifest.xml:
<meta-data android:name="com.mixpanel.android.MPConfig.DisableAppOpenEvent" android:value="false" />
App Open from Push Notification
Our SDKs will track an $app_open event if a user clicks the push notification to open the app. On our iOS libraries the $app_open event will only fire if launchOptions are passed to the initialization of your Mixpanel instance. Our Android SDK will fire the $app_open event automatically if using a v4.9.5 or greater. These $app_open events will include a campaign_id event property ("Message" in Mixpanel UI) that can be used to differentiate from other $app_open events.
For more information around push open tracking, please visit our page on push open tracking.
On iOS within applicationWillTerminate and applicationDidEnterBackground (to capture both full closes and backgrounds).
On Android within onDestroy.
Note: Are you tracking app closes to determine session length tracking? If so read more about tracking session length with Mixpanel.
Article is closed for comments.