Class MixpanelAPI

java.lang.Object
com.mixpanel.android.mpmetrics.MixpanelAPI

public class MixpanelAPI extends Object
Core class for interacting with Mixpanel Analytics.

Call getInstance(Context, String, boolean) with your main application activity and your Mixpanel API token as arguments an to get an instance you can use to report how users are using your application.

Once you have an instance, you can send events to Mixpanel using track(String, JSONObject), and update People Analytics records with getPeople()

The Mixpanel library will periodically send information to Mixpanel servers, so your application will need to have android.permission.INTERNET. In addition, to preserve battery life, messages to Mixpanel servers may not be sent immediately when you call track(String)or MixpanelAPI.People.set(String, Object). The library will send messages periodically throughout the lifetime of your application, but you will need to call flush() before your application is completely shutdown to ensure all of your events are sent.

A typical use-case for the library might look like this:

 
 public class MainActivity extends Activity {
      MixpanelAPI mMixpanel;

      public void onCreate(Bundle saved) {
          mMixpanel = MixpanelAPI.getInstance(this, "YOUR MIXPANEL API TOKEN");
          ...
      }

      public void whenSomethingInterestingHappens(int flavor) {
          JSONObject properties = new JSONObject();
          properties.put("flavor", flavor);
          mMixpanel.track("Something Interesting Happened", properties);
          ...
      }

      public void onDestroy() {
          mMixpanel.flush();
          super.onDestroy();
      }
 }
 
 

In addition to this documentation, you may wish to take a look at the Mixpanel sample Android application. It demonstrates a variety of techniques, including updating People Analytics records with MixpanelAPI.People and others.

There are also step-by-step getting started documents available at mixpanel.com

See Also:
  • Field Details

  • Method Details

    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, String instanceName, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      instanceName - The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, boolean optOutTrackingDefault, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      optOutTrackingDefault - Whether or not Mixpanel can start tracking by default. See optOutTracking().
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, boolean optOutTrackingDefault, String instanceName, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      optOutTrackingDefault - Whether or not Mixpanel can start tracking by default. See optOutTracking().
      instanceName - The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token.
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, org.json.JSONObject superProperties, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      superProperties - A JSONObject containing super properties to register.
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, org.json.JSONObject superProperties, String instanceName, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      superProperties - A JSONObject containing super properties to register.
      instanceName - The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • getInstance

      public static MixpanelAPI getInstance(android.content.Context context, String token, boolean optOutTrackingDefault, org.json.JSONObject superProperties, String instanceName, boolean trackAutomaticEvents)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.

      Use getInstance to get a reference to a shared instance of MixpanelAPI you can use to send events and People Analytics updates to Mixpanel.

      getInstance is thread safe, but the returned instance is not, and may be shared with other callers of getInstance. The best practice is to call getInstance, and use the returned MixpanelAPI, object from a single thread (probably the main UI thread of your application).

      If you do choose to track events from multiple threads in your application, you should synchronize your calls on the instance itself, like so:

       
       MixpanelAPI instance = MixpanelAPI.getInstance(context, token);
       synchronized(instance) { // Only necessary if the instance will be used in multiple threads.
           instance.track(...)
       }
       
       
      Parameters:
      context - The application context you are tracking
      token - Your Mixpanel project token. You can get your project token on the Mixpanel web site, in the settings dialog.
      optOutTrackingDefault - Whether or not Mixpanel can start tracking by default. See optOutTracking().
      superProperties - A JSONObject containing super properties to register.
      instanceName - The name you want to uniquely identify the Mixpanel Instance. It is useful when you want more than one Mixpanel instance under the same project token
      trackAutomaticEvents - Whether or not to collect common mobile events include app sessions, first app opens, app updated, etc.
      Returns:
      an instance of MixpanelAPI associated with your project
    • setUseIpAddressForGeolocation

      public void setUseIpAddressForGeolocation(boolean useIpAddressForGeolocation)
      Controls whether to automatically send the client IP Address as part of event tracking.

      With an IP address, geo-location is possible down to neighborhoods within a city, although the Mixpanel Dashboard will just show you city level location specificity.

      Parameters:
      useIpAddressForGeolocation - If true, automatically send the client IP Address. Defaults to true.
    • setEnableLogging

      public void setEnableLogging(boolean enableLogging)
      Controls whether to enable the run time debug logging
      Parameters:
      enableLogging - If true, emit more detailed log messages. Defaults to false
    • setFlushBatchSize

      public void setFlushBatchSize(int flushBatchSize)
      Set maximum number of events/updates to send in a single network request
      Parameters:
      flushBatchSize - int, the number of events to be flushed at a time, defaults to 50
    • getFlushBatchSize

      public int getFlushBatchSize()
      Get maximum number of events/updates to send in a single network request
      Returns:
      the integer number of events to be flushed at a time
    • setMaximumDatabaseLimit

      public void setMaximumDatabaseLimit(int maximumDatabaseLimit)
      Set an integer number of bytes, the maximum size limit to the Mixpanel database.
      Parameters:
      maximumDatabaseLimit - an integer number of bytes, the maximum size limit to the Mixpanel database.
    • getMaximumDatabaseLimit

      public int getMaximumDatabaseLimit()
      Get the maximum size limit to the Mixpanel database.
      Returns:
      an integer number of bytes, the maximum size limit to the Mixpanel database.
    • setServerURL

      public void setServerURL(String serverURL)
      Set the base URL used for Mixpanel API requests. Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com. To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
      Parameters:
      serverURL - the base URL used for Mixpanel API requests
    • setServerURL

      public void setServerURL(String serverURL, ProxyServerInteractor callback)
      Set the base URL used for Mixpanel API requests. Useful if you need to proxy Mixpanel requests. Defaults to https://api.mixpanel.com. To route data to Mixpanel's EU servers, set to https://api-eu.mixpanel.com
      Parameters:
      serverURL - the base URL used for Mixpanel API requests
      callback - the callback for mixpanel proxy server api headers and status
    • getTrackAutomaticEvents

      public Boolean getTrackAutomaticEvents()
    • alias

      public void alias(String alias, String distinct_id)
      This function creates a distinct_id alias from alias to distinct_id. If distinct_id is null, then it will create an alias to the current events distinct_id, which may be the distinct_id randomly generated by the Mixpanel library before identify(String) is called.

      This call does not identify the user after. You must still call identify(String) if you wish the new alias to be used for Events and People.

      Parameters:
      alias - the new value that should represent distinct_id.
      distinct_id - the old distinct_id that alias will be mapped to.
    • identify

      public void identify(String distinctId)
      Equivalent to identify(String, boolean) with a true argument for usePeople.

      By default, this method will also associate future calls to MixpanelAPI.People.set(JSONObject), MixpanelAPI.People.increment(Map), MixpanelAPI.People.append(String, Object), etc... with a particular People Analytics user with the distinct id. If you do not want to do that, you must call identify(String, boolean) with false for second argument. NOTE: This behavior changed in version 6.2.0, previously MixpanelAPI.People.identify(String) had to be called separately.

      Parameters:
      distinctId - a string uniquely identifying this user. Events sent to Mixpanel or Users identified using the same distinct id will be considered associated with the same visitor/customer for retention and funnel reporting, so be sure that the given value is globally unique for each individual user you intend to track.
    • identify

      public void identify(String distinctId, boolean usePeople)
      Associate all future calls to track(String, JSONObject) with the user identified by the given distinct id.

      Calls to track(String, JSONObject) made before corresponding calls to identify will use an anonymous locally generated distinct id, which means it is best to call identify early to ensure that your Mixpanel funnels and retention analytics can continue to track the user throughout their lifetime. We recommend calling identify when the user authenticates.

      Once identify is called, the local distinct id persists across restarts of your application.

      Parameters:
      distinctId - a string uniquely identifying this user. Events sent to Mixpanel using the same disinct id will be considered associated with the same visitor/customer for retention and funnel reporting, so be sure that the given value is globally unique for each individual user you intend to track.
      usePeople - boolean indicating whether or not to also call MixpanelAPI.People.identify(String)
    • timeEvent

      public void timeEvent(String eventName)
      Begin timing of an event. Calling timeEvent("Thing") will not send an event, but when you eventually call track("Thing"), your tracked event will be sent with a "$duration" property, representing the number of seconds between your calls.
      Parameters:
      eventName - the name of the event to track with timing.
    • clearTimedEvents

      public void clearTimedEvents()
      Clears all current event timings.
    • clearTimedEvent

      public void clearTimedEvent(String eventName)
      Clears the event timing for an event.
      Parameters:
      eventName - the name of the timed event to clear.
    • eventElapsedTime

      public double eventElapsedTime(String eventName)
      Retrieves the time elapsed for the named event since timeEvent() was called.
      Parameters:
      eventName - the name of the event to be tracked that was previously called with timeEvent()
      Returns:
      Time elapsed since timeEvent(String) was called for the given eventName.
    • trackMap

      public void trackMap(String eventName, Map<String,Object> properties)
      Track an event.

      Every call to track eventually results in a data point sent to Mixpanel. These data points are what are measured, counted, and broken down to create your Mixpanel reports. Events have a string name, and an optional set of name/value pairs that describe the properties of that event.

      Parameters:
      eventName - The name of the event to send
      properties - A Map containing the key value pairs of the properties to include in this event. Pass null if no extra properties exist. See also track(String, org.json.JSONObject)
    • trackWithGroups

      public void trackWithGroups(String eventName, Map<String,Object> properties, Map<String,Object> groups)
      Track an event with specific groups.

      Every call to track eventually results in a data point sent to Mixpanel. These data points are what are measured, counted, and broken down to create your Mixpanel reports. Events have a string name, and an optional set of name/value pairs that describe the properties of that event. Group key/value pairs are upserted into the property map before tracking.

      Parameters:
      eventName - The name of the event to send
      properties - A Map containing the key value pairs of the properties to include in this event. Pass null if no extra properties exist.
      groups - A Map containing the group key value pairs for this event. See also track(String, org.json.JSONObject), trackMap(String, Map)
    • track

      public void track(String eventName, org.json.JSONObject properties)
      Track an event.

      Every call to track eventually results in a data point sent to Mixpanel. These data points are what are measured, counted, and broken down to create your Mixpanel reports. Events have a string name, and an optional set of name/value pairs that describe the properties of that event.

      Parameters:
      eventName - The name of the event to send
      properties - A JSONObject containing the key value pairs of the properties to include in this event. Pass null if no extra properties exist.
    • track

      public void track(String eventName)
      Equivalent to track(String, JSONObject) with a null argument for properties. Consider adding properties to your tracking to get the best insights and experience from Mixpanel.
      Parameters:
      eventName - the name of the event to send
    • flush

      public void flush()
      Push all queued Mixpanel events and People Analytics changes to Mixpanel servers.

      Events and People messages are pushed gradually throughout the lifetime of your application. This means that to ensure that all messages are sent to Mixpanel when your application is shut down, you will need to call flush() to let the Mixpanel library know it should send all remaining messages to the server. We strongly recommend placing a call to flush() in the onDestroy() method of your main application activity.

    • getSuperProperties

      public org.json.JSONObject getSuperProperties()
      Returns a json object of the user's current super properties

      SuperProperties are a collection of properties that will be sent with every event to Mixpanel, and persist beyond the lifetime of your application.

      Returns:
      Super properties for this Mixpanel instance.
    • getDistinctId

      public String getDistinctId()
      Returns the string id currently being used to uniquely identify the user. Before any calls to identify(String), this will be an id automatically generated by the library.
      Returns:
      The distinct id that uniquely identifies the current user.
      See Also:
    • getAnonymousId

      public String getAnonymousId()
      Returns the anonymoous id currently being used to uniquely identify the device and all with events sent using track(String, JSONObject) will have this id as a device id
      Returns:
      The device id associated with event tracking
    • getUserId

      protected String getUserId()
      Returns the user id with which identify is called and all the with events sent using track(String, JSONObject) will have this id as a user id
      Returns:
      The user id associated with event tracking
    • registerSuperPropertiesMap

      public void registerSuperPropertiesMap(Map<String,Object> superProperties)
      Register properties that will be sent with every subsequent call to track(String, JSONObject).

      SuperProperties are a collection of properties that will be sent with every event to Mixpanel, and persist beyond the lifetime of your application.

      Setting a superProperty with registerSuperProperties will store a new superProperty, possibly overwriting any existing superProperty with the same name (to set a superProperty only if it is currently unset, use registerSuperPropertiesOnce(JSONObject))

      SuperProperties will persist even if your application is taken completely out of memory. to remove a superProperty, call unregisterSuperProperty(String) or clearSuperProperties()

      Parameters:
      superProperties - A Map containing super properties to register See also registerSuperProperties(org.json.JSONObject)
    • registerSuperProperties

      public void registerSuperProperties(org.json.JSONObject superProperties)
      Register properties that will be sent with every subsequent call to track(String, JSONObject).

      SuperProperties are a collection of properties that will be sent with every event to Mixpanel, and persist beyond the lifetime of your application.

      Setting a superProperty with registerSuperProperties will store a new superProperty, possibly overwriting any existing superProperty with the same name (to set a superProperty only if it is currently unset, use registerSuperPropertiesOnce(JSONObject))

      SuperProperties will persist even if your application is taken completely out of memory. to remove a superProperty, call unregisterSuperProperty(String) or clearSuperProperties()

      Parameters:
      superProperties - A JSONObject containing super properties to register
      See Also:
    • unregisterSuperProperty

      public void unregisterSuperProperty(String superPropertyName)
      Remove a single superProperty, so that it will not be sent with future calls to track(String, JSONObject).

      If there is a superProperty registered with the given name, it will be permanently removed from the existing superProperties. To clear all superProperties, use clearSuperProperties()

      Parameters:
      superPropertyName - name of the property to unregister
      See Also:
    • registerSuperPropertiesOnceMap

      public void registerSuperPropertiesOnceMap(Map<String,Object> superProperties)
      Register super properties for events, only if no other super property with the same names has already been registered.

      Calling registerSuperPropertiesOnce will never overwrite existing properties.

      Parameters:
      superProperties - A Map containing the super properties to register. See also registerSuperPropertiesOnce(org.json.JSONObject)
    • registerSuperPropertiesOnce

      public void registerSuperPropertiesOnce(org.json.JSONObject superProperties)
      Register super properties for events, only if no other super property with the same names has already been registered.

      Calling registerSuperPropertiesOnce will never overwrite existing properties.

      Parameters:
      superProperties - A JSONObject containing the super properties to register.
      See Also:
    • clearSuperProperties

      public void clearSuperProperties()
      Erase all currently registered superProperties.

      Future tracking calls to Mixpanel will not contain the specific superProperties registered before the clearSuperProperties method was called.

      To remove a single superProperty, use unregisterSuperProperty(String)

      See Also:
    • updateSuperProperties

      public void updateSuperProperties(SuperPropertyUpdate update)
      Updates super properties in place. Given a SuperPropertyUpdate object, will pass the current values of SuperProperties to that update and replace all results with the return value of the update. Updates are synchronized on the underlying super properties store, so they are guaranteed to be thread safe (but long running updates may slow down your tracking.)
      Parameters:
      update - A function from one set of super properties to another. The update should not return null.
    • setGroup

      public void setGroup(String groupKey, Object groupID)
      Set the group this user belongs to.
      Parameters:
      groupKey - The property name associated with this group type (must already have been set up).
      groupID - The group the user belongs to.
    • setGroup

      public void setGroup(String groupKey, List<Object> groupIDs)
      Set the groups this user belongs to.
      Parameters:
      groupKey - The property name associated with this group type (must already have been set up).
      groupIDs - The list of groups the user belongs to.
    • addGroup

      public void addGroup(String groupKey, Object groupID)
      Add a group to this user's membership for a particular group key
      Parameters:
      groupKey - The property name associated with this group type (must already have been set up).
      groupID - The new group the user belongs to.
    • removeGroup

      public void removeGroup(String groupKey, Object groupID)
      Remove a group from this user's membership for a particular group key
      Parameters:
      groupKey - The property name associated with this group type (must already have been set up).
      groupID - The group value to remove.
    • getPeople

      public MixpanelAPI.People getPeople()
      Returns a Mixpanel.People object that can be used to set and increment People Analytics properties.
      Returns:
      an instance of MixpanelAPI.People that you can use to update records in Mixpanel People Analytics.
    • getGroup

      public MixpanelAPI.Group getGroup(String groupKey, Object groupID)
      Returns a Mixpanel.Group object that can be used to set and increment Group Analytics properties.
      Parameters:
      groupKey - String identifying the type of group (must be already in use as a group key)
      groupID - Object identifying the specific group
      Returns:
      an instance of MixpanelAPI.Group that you can use to update records in Mixpanel Group Analytics
    • reset

      public void reset()
      Clears tweaks and all distinct_ids, superProperties, and push registrations from persistent storage. Will not clear referrer information.
    • getDeviceInfo

      public Map<String,String> getDeviceInfo()
      Returns an unmodifiable map that contains the device description properties that will be sent to Mixpanel. These are not all of the default properties, but are a subset that are dependant on the user's device or installed version of the host application, and are guaranteed not to change while the app is running.
      Returns:
      Map containing the device description properties that are sent to Mixpanel.
    • optOutTracking

      public void optOutTracking()
      Use this method to opt-out a user from tracking. Events and people updates that haven't been flushed yet will be deleted. Use flush() before calling this method if you want to send all the queues to Mixpanel before. This method will also remove any user-related information from the device.
    • optInTracking

      public void optInTracking()
      Use this method to opt-in an already opted-out user from tracking. People updates and track calls will be sent to Mixpanel after using this method. This method will internally track an opt-in event to your project. If you want to identify the opt-in event and/or pass properties to the event, see optInTracking(String) and optInTracking(String, JSONObject) See also optOutTracking().
    • optInTracking

      public void optInTracking(String distinctId)
      Use this method to opt-in an already opted-out user from tracking. People updates and track calls will be sent to Mixpanel after using this method. This method will internally track an opt-in event to your project.
      Parameters:
      distinctId - Optional string to use as the distinct ID for events. This will call identify(String). See also optInTracking(String), optInTracking(String, JSONObject) and optOutTracking().
    • optInTracking

      public void optInTracking(String distinctId, org.json.JSONObject properties)
      Use this method to opt-in an already opted-out user from tracking. People updates and track calls will be sent to Mixpanel after using this method. This method will internally track an opt-in event to your project.
      Parameters:
      distinctId - Optional string to use as the distinct ID for events. This will call identify(String).
      properties - Optional JSONObject that could be passed to add properties to the opt-in event that is sent to Mixpanel. See also optInTracking() and optOutTracking().
    • hasOptedOutTracking

      public boolean hasOptedOutTracking()
      Will return true if the user has opted out from tracking. See optOutTracking() and getInstance(Context, String, boolean, JSONObject, String, boolean) for more information.
      Returns:
      true if user has opted out from tracking. Defaults to false.
    • isAppInForeground

      public boolean isAppInForeground()
      Based on the application's event lifecycle this method will determine whether the app is running in the foreground or not. If your build version is below 14 this method will always return false.
      Returns:
      True if the app is running in the foreground.
    • track

      protected void track(String eventName, org.json.JSONObject properties, boolean isAutomaticEvent)