Class MixpanelAPI

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  MixpanelAPI.Group
      Core interface for using Mixpanel Group Analytics features.
      static interface  MixpanelAPI.People
      Core interface for using Mixpanel People Analytics features.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String VERSION
      String version of the library.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addGroup​(java.lang.String groupKey, java.lang.Object groupID)
      Add a group to this user's membership for a particular group key
      void alias​(java.lang.String alias, java.lang.String original)
      This function creates a distinct_id alias from alias to original.
      static Tweak<java.lang.Boolean> booleanTweak​(java.lang.String tweakName, boolean defaultValue)
      Declare a boolean-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.Byte> byteTweak​(java.lang.String tweakName, byte defaultValue)
      Declare byte-valued tweak, and return a reference you can use to read the value of the tweak.
      void clearSuperProperties()
      Erase all currently registered superProperties.
      static Tweak<java.lang.Double> doubleTweak​(java.lang.String tweakName, double defaultValue)
      Declare a double-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.Double> doubleTweak​(java.lang.String tweakName, double defaultValue, double minimumValue, double maximumValue)
      Declare a double-valued tweak, and return a reference you can use to read the value of the tweak.
      double eventElapsedTime​(java.lang.String eventName)
      Retrieves the time elapsed for the named event since timeEvent() was called.
      static Tweak<java.lang.Float> floatTweak​(java.lang.String tweakName, float defaultValue)
      Declare a float-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.Float> floatTweak​(java.lang.String tweakName, float defaultValue, float minimumValue, float maximumValue)
      Declare a float-valued tweak, and return a reference you can use to read the value of the tweak.
      void flush()
      Push all queued Mixpanel events and People Analytics changes to Mixpanel servers.
      protected void flushNoDecideCheck()  
      protected java.lang.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
      java.util.Map<java.lang.String,​java.lang.String> getDeviceInfo()
      Returns an unmodifiable map that contains the device description properties that will be sent to Mixpanel.
      java.lang.String getDistinctId()
      Returns the string id currently being used to uniquely identify the user associated with events sent using track(String, JSONObject).
      MixpanelAPI.Group getGroup​(java.lang.String groupKey, java.lang.Object groupID)
      Returns a Mixpanel.Group object that can be used to set and increment Group Analytics properties.
      static MixpanelAPI getInstance​(android.content.Context context, java.lang.String token)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.
      static MixpanelAPI getInstance​(android.content.Context context, java.lang.String token, boolean optOutTrackingDefault)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.
      static MixpanelAPI getInstance​(android.content.Context context, java.lang.String token, boolean optOutTrackingDefault, org.json.JSONObject superProperties)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.
      static MixpanelAPI getInstance​(android.content.Context context, java.lang.String token, org.json.JSONObject superProperties)
      Get the instance of MixpanelAPI associated with your Mixpanel project token.
      MixpanelAPI.People getPeople()
      Returns a Mixpanel.People object that can be used to set and increment People Analytics properties.
      org.json.JSONObject getSuperProperties()
      Returns a json object of the user's current super properties
      protected java.lang.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
      boolean hasOptedOutTracking()
      Will return true if the user has opted out from tracking.
      void identify​(java.lang.String distinctId)
      Associate all future calls to track(String, JSONObject) with the user identified by the given distinct id.
      static Tweak<java.lang.Integer> intTweak​(java.lang.String tweakName, int defaultValue)
      Declare an int-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.Integer> intTweak​(java.lang.String tweakName, int defaultValue, int minimumValue, int maximumValue)
      Declare an int-valued tweak, and return a reference you can use to read the value of the tweak.
      boolean isAppInForeground()
      Based on the application's event lifecycle this method will determine whether the app is running in the foreground or not.
      static Tweak<java.lang.Long> longTweak​(java.lang.String tweakName, long defaultValue)
      Declare a long-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.Long> longTweak​(java.lang.String tweakName, long defaultValue, long minimumValue, long maximumValue)
      Declare a long-valued tweak, and return a reference you can use to read the value of the tweak.
      void optInTracking()
      Use this method to opt-in an already opted-out user from tracking.
      void optInTracking​(java.lang.String distinctId)
      Use this method to opt-in an already opted-out user from tracking.
      void optInTracking​(java.lang.String distinctId, org.json.JSONObject properties)
      Use this method to opt-in an already opted-out user from tracking.
      void optOutTracking()
      Use this method to opt-out a user from tracking.
      void registerSuperProperties​(org.json.JSONObject superProperties)
      Register properties that will be sent with every subsequent call to track(String, JSONObject).
      void registerSuperPropertiesMap​(java.util.Map<java.lang.String,​java.lang.Object> superProperties)
      Register properties that will be sent with every subsequent call to track(String, JSONObject).
      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.
      void registerSuperPropertiesOnceMap​(java.util.Map<java.lang.String,​java.lang.Object> superProperties)
      Register super properties for events, only if no other super property with the same names has already been registered.
      void removeGroup​(java.lang.String groupKey, java.lang.Object groupID)
      Remove a group from this user's membership for a particular group key
      void reset()
      Clears tweaks and all distinct_ids, superProperties, and push registrations from persistent storage.
      void setEnableLogging​(boolean enableLogging)
      Controls whether to enable the run time debug logging
      void setGroup​(java.lang.String groupKey, java.lang.Object groupID)
      Set the group this user belongs to.
      void setGroup​(java.lang.String groupKey, java.util.List<java.lang.Object> groupIDs)
      Set the groups this user belongs to.
      void setServerURL​(java.lang.String serverURL)
      Set the base URL used for Mixpanel API requests.
      void setUseIpAddressForGeolocation​(boolean useIpAddressForGeolocation)
      Controls whether to automatically send the client IP Address as part of event tracking.
      static Tweak<java.lang.Short> shortTweak​(java.lang.String tweakName, short defaultValue)
      Declare short-valued tweak, and return a reference you can use to read the value of the tweak.
      static Tweak<java.lang.String> stringTweak​(java.lang.String tweakName, java.lang.String defaultValue)
      Declare a string-valued tweak, and return a reference you can use to read the value of the tweak.
      void timeEvent​(java.lang.String eventName)
      Begin timing of an event.
      void track​(java.lang.String eventName)
      Equivalent to track(String, JSONObject) with a null argument for properties.
      void track​(java.lang.String eventName, org.json.JSONObject properties)
      Track an event.
      protected void track​(java.lang.String eventName, org.json.JSONObject properties, boolean isAutomaticEvent)  
      void trackMap​(java.lang.String eventName, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Track an event.
      void trackWithGroups​(java.lang.String eventName, java.util.Map<java.lang.String,​java.lang.Object> properties, java.util.Map<java.lang.String,​java.lang.Object> groups)
      Track an event with specific groups.
      void unregisterSuperProperty​(java.lang.String superPropertyName)
      Remove a single superProperty, so that it will not be sent with future calls to track(String, JSONObject).
      void updateSuperProperties​(SuperPropertyUpdate update)
      Updates super properties in place.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • VERSION

        public static final java.lang.String VERSION
        String version of the library.
        See Also:
        Constant Field Values
    • Method Detail

      • stringTweak

        public static Tweak<java.lang.String> stringTweak​(java.lang.String tweakName,
                                                          java.lang.String defaultValue)
        Declare a string-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • booleanTweak

        public static Tweak<java.lang.Boolean> booleanTweak​(java.lang.String tweakName,
                                                            boolean defaultValue)
        Declare a boolean-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • doubleTweak

        public static Tweak<java.lang.Double> doubleTweak​(java.lang.String tweakName,
                                                          double defaultValue)
        Declare a double-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • doubleTweak

        public static Tweak<java.lang.Double> doubleTweak​(java.lang.String tweakName,
                                                          double defaultValue,
                                                          double minimumValue,
                                                          double maximumValue)
        Declare a double-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        minimumValue - Minimum numeric value of your tweak.
        maximumValue - Maximum numeric value of your tweak.
        Returns:
        A new or existing tweak object.
      • floatTweak

        public static Tweak<java.lang.Float> floatTweak​(java.lang.String tweakName,
                                                        float defaultValue)
        Declare a float-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • floatTweak

        public static Tweak<java.lang.Float> floatTweak​(java.lang.String tweakName,
                                                        float defaultValue,
                                                        float minimumValue,
                                                        float maximumValue)
        Declare a float-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        minimumValue - Minimum numeric value of your tweak.
        maximumValue - Maximum numeric value of your tweak.
        Returns:
        A new or existing tweak object.
      • longTweak

        public static Tweak<java.lang.Long> longTweak​(java.lang.String tweakName,
                                                      long defaultValue)
        Declare a long-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • longTweak

        public static Tweak<java.lang.Long> longTweak​(java.lang.String tweakName,
                                                      long defaultValue,
                                                      long minimumValue,
                                                      long maximumValue)
        Declare a long-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        minimumValue - Minimum numeric value of your tweak.
        maximumValue - Maximum numeric value of your tweak.
        Returns:
        A new or existing tweak object.
      • intTweak

        public static Tweak<java.lang.Integer> intTweak​(java.lang.String tweakName,
                                                        int defaultValue)
        Declare an int-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • intTweak

        public static Tweak<java.lang.Integer> intTweak​(java.lang.String tweakName,
                                                        int defaultValue,
                                                        int minimumValue,
                                                        int maximumValue)
        Declare an int-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        minimumValue - Minimum numeric value of your tweak.
        maximumValue - Maximum numeric value of your tweak.
        Returns:
        A new or existing tweak object.
      • shortTweak

        public static Tweak<java.lang.Short> shortTweak​(java.lang.String tweakName,
                                                        short defaultValue)
        Declare short-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • byteTweak

        public static Tweak<java.lang.Byte> byteTweak​(java.lang.String tweakName,
                                                      byte defaultValue)
        Declare byte-valued tweak, and return a reference you can use to read the value of the tweak. Tweaks can be changed in Mixpanel A/B tests, and can allow you to alter your customers' experience in your app without re-deploying your application through the app store.
        Parameters:
        tweakName - Unique name to identify your tweak.
        defaultValue - Default value of your tweak.
        Returns:
        A new or existing tweak object.
      • getInstance

        public static MixpanelAPI getInstance​(android.content.Context context,
                                              java.lang.String token)
        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.
        Returns:
        an instance of MixpanelAPI associated with your project
      • getInstance

        public static MixpanelAPI getInstance​(android.content.Context context,
                                              java.lang.String token,
                                              boolean optOutTrackingDefault)
        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().
        Returns:
        an instance of MixpanelAPI associated with your project
      • getInstance

        public static MixpanelAPI getInstance​(android.content.Context context,
                                              java.lang.String token,
                                              org.json.JSONObject superProperties)
        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.
        Returns:
        an instance of MixpanelAPI associated with your project
      • getInstance

        public static MixpanelAPI getInstance​(android.content.Context context,
                                              java.lang.String token,
                                              boolean optOutTrackingDefault,
                                              org.json.JSONObject superProperties)
        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.
        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
      • setServerURL

        public void setServerURL​(java.lang.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
      • alias

        public void alias​(java.lang.String alias,
                          java.lang.String original)
        This function creates a distinct_id alias from alias to original. If original 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 both identify(String) and MixpanelAPI.People.identify(String) if you wish the new alias to be used for Events and People.

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

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

        This call does not identify the user for People Analytics; to do that, see MixpanelAPI.People.identify(String). Mixpanel recommends using the same distinct_id for both calls, and using a distinct_id that is easy to associate with the given user, for example, a server-side account identifier.

        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.
        See Also:
        MixpanelAPI.People.identify(String)
      • timeEvent

        public void timeEvent​(java.lang.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.
      • eventElapsedTime

        public double eventElapsedTime​(java.lang.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​(java.lang.String eventName,
                             java.util.Map<java.lang.String,​java.lang.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​(java.lang.String eventName,
                                    java.util.Map<java.lang.String,​java.lang.Object> properties,
                                    java.util.Map<java.lang.String,​java.lang.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​(java.lang.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​(java.lang.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.
      • getAnonymousId

        protected java.lang.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 java.lang.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​(java.util.Map<java.lang.String,​java.lang.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)
      • unregisterSuperProperty

        public void unregisterSuperProperty​(java.lang.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:
        registerSuperProperties(JSONObject)
      • registerSuperPropertiesOnceMap

        public void registerSuperPropertiesOnceMap​(java.util.Map<java.lang.String,​java.lang.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:
        registerSuperProperties(JSONObject)
      • 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:
        registerSuperProperties(JSONObject)
      • 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​(java.lang.String groupKey,
                             java.lang.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​(java.lang.String groupKey,
                             java.util.List<java.lang.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​(java.lang.String groupKey,
                             java.lang.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​(java.lang.String groupKey,
                                java.lang.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 and manage Mixpanel Firebase Cloud Messaging notifications.
      • getGroup

        public MixpanelAPI.Group getGroup​(java.lang.String groupKey,
                                          java.lang.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 java.util.Map<java.lang.String,​java.lang.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​(java.lang.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). If you use people profiles make sure you manually call MixpanelAPI.People.identify(String) after this method.
        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().
      • 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.
      • flushNoDecideCheck

        protected void flushNoDecideCheck()
      • track

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