Interface MixpanelAPI.People

  • Enclosing class:
    MixpanelAPI

    public static interface MixpanelAPI.People
    Core interface for using Mixpanel People Analytics features. You can get an instance by calling MixpanelAPI.getPeople()

    The People object is used to update properties in a user's People Analytics record, and to manage the receipt of push notifications sent via Mixpanel Engage. For this reason, it's important to call identify(String) on the People object before you work with it. Once you call identify, the user identity will persist across stops and starts of your application, until you make another call to identify using a different id. A typical use case for the People object might look like this:

     
    
     public class MainActivity extends Activity {
          MixpanelAPI mMixpanel;
    
          public void onCreate(Bundle saved) {
              mMixpanel = MixpanelAPI.getInstance(this, "YOUR MIXPANEL API TOKEN");
              mMixpanel.getPeople().identify("A UNIQUE ID FOR THIS USER");
              ...
          }
    
          public void userUpdatedJobTitle(String newTitle) {
              mMixpanel.getPeople().set("Job Title", newTitle);
              ...
          }
    
          public void onDestroy() {
              mMixpanel.flush();
              super.onDestroy();
          }
     }
    
     
     
    See Also:
    MixpanelAPI
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addOnMixpanelTweaksUpdatedListener​(OnMixpanelTweaksUpdatedListener listener)
      Sets the listener that will receive a callback when new Tweaks from Mixpanel are discovered.
      void addOnMixpanelUpdatesReceivedListener​(OnMixpanelUpdatesReceivedListener listener)
      Adds a new listener that will receive a callback when new updates from Mixpanel (like in-app notifications or A/B test experiments) are discovered.
      void append​(java.lang.String name, java.lang.Object value)
      Appends a value to a list-valued property.
      void clearCharges()
      Permanently clear the whole transaction history for the identified people profile.
      void clearPushRegistrationId()
      Manually clear all current Firebase Cloud Messaging tokens from Mixpanel.
      void clearPushRegistrationId​(java.lang.String registrationId)
      Manually clear a single Firebase Cloud Messaging token from Mixpanel.
      void deleteUser()
      Permanently deletes the identified user's record from People Analytics.
      java.lang.String getDistinctId()
      Returns the string id currently being used to uniquely identify the user associated with events sent using set(String, Object) and increment(String, double).
      InAppNotification getNotificationIfAvailable()
      Returns an InAppNotification object if one is available and being held by the library, or null if no notification is currently available.
      java.lang.String getPushRegistrationId()
      Retrieves current Firebase Cloud Messaging token.
      void identify​(java.lang.String distinctId)
      Associate future calls to set(JSONObject), increment(Map), append(String, Object), etc...
      void increment​(java.lang.String name, double increment)
      Add the given amount to an existing property on the identified user.
      void increment​(java.util.Map<java.lang.String,​? extends java.lang.Number> properties)
      Change the existing values of multiple People Analytics properties at once.
      boolean isIdentified()
      Checks if the people profile is identified or not.
      void joinExperimentIfAvailable()
      Applies A/B test changes, if they are present.
      void merge​(java.lang.String name, org.json.JSONObject updates)
      Merge a given JSONObject into the object-valued property named name.
      void remove​(java.lang.String name, java.lang.Object value)
      Remove value from a list-valued property only if they are already present in the list.
      void removeOnMixpanelTweaksUpdatedListener​(OnMixpanelTweaksUpdatedListener listener)
      Removes the listener previously registered with addOnMixpanelTweaksUpdatedListener.
      void removeOnMixpanelUpdatesReceivedListener​(OnMixpanelUpdatesReceivedListener listener)
      Removes a listener previously registered with addOnMixpanelUpdatesReceivedListener.
      void set​(java.lang.String propertyName, java.lang.Object value)
      Sets a single property with the given name and value for this user.
      void set​(org.json.JSONObject properties)
      Set a collection of properties on the identified user all at once.
      void setMap​(java.util.Map<java.lang.String,​java.lang.Object> properties)
      Set a collection of properties on the identified user all at once.
      void setOnce​(java.lang.String propertyName, java.lang.Object value)
      Works just like set(String, Object), except it will not overwrite existing property values.
      void setOnce​(org.json.JSONObject properties)
      Like set(String, Object), but will not set properties that already exist on a record.
      void setOnceMap​(java.util.Map<java.lang.String,​java.lang.Object> properties)
      Like set(String, Object), but will not set properties that already exist on a record.
      void setPushRegistrationId​(java.lang.String token)
      Manually send a Firebase Cloud Messaging token to Mixpanel.
      void showGivenNotification​(InAppNotification notif, android.app.Activity parent)
      Shows the given in-app notification to the user.
      void showNotificationById​(int id, android.app.Activity parent)
      Shows an in-app notification identified by id.
      void showNotificationIfAvailable​(android.app.Activity parent)
      Shows an in-app notification to the user if one is available.
      void trackCharge​(double amount, org.json.JSONObject properties)
      Track a revenue transaction for the identified people profile.
      void trackNotification​(java.lang.String eventName, InAppNotification notif, org.json.JSONObject properties)
      Sends an event to Mixpanel that includes the automatic properties associated with the given notification.
      void trackNotificationSeen​(InAppNotification notif)
      Tells MixPanel that you have handled an InAppNotification in the case where you are manually dealing with your notifications (getNotificationIfAvailable()).
      void union​(java.lang.String name, org.json.JSONArray value)
      Adds values to a list-valued property only if they are not already present in the list.
      void unset​(java.lang.String name)
      permanently removes the property with the given name from the user's profile
      MixpanelAPI.People withIdentity​(java.lang.String distinctId)
      Return an instance of Mixpanel people with a temporary distinct id.
    • Method Detail

      • identify

        void identify​(java.lang.String distinctId)
        Associate future calls to set(JSONObject), increment(Map), append(String, Object), etc... with a particular People Analytics user.

        All future calls to the People object will rely on this value to assign and increment properties. The user identification will persist across restarts of your application. We recommend calling People.identify as soon as you know the distinct id of the user.

        Parameters:
        distinctId - a String that uniquely identifies the user. Users identified with the same distinct id will be considered to be the same user in Mixpanel, across all platforms and devices. We recommend choosing a distinct id that is meaningful to your other systems (for example, a server-side account identifier), and using the same distinct id for both calls to People.identify and MixpanelAPI.identify(String)
        See Also:
        MixpanelAPI.identify(String)
      • set

        void set​(java.lang.String propertyName,
                 java.lang.Object value)
        Sets a single property with the given name and value for this user. The given name and value will be assigned to the user in Mixpanel People Analytics, possibly overwriting an existing property with the same name.
        Parameters:
        propertyName - The name of the Mixpanel property. This must be a String, for example "Zip Code"
        value - The value of the Mixpanel property. For "Zip Code", this value might be the String "90210"
      • setMap

        void setMap​(java.util.Map<java.lang.String,​java.lang.Object> properties)
        Set a collection of properties on the identified user all at once.
        Parameters:
        properties - a Map containing the collection of properties you wish to apply to the identified user. Each key in the Map will be associated with a property name, and the value of that key will be assigned to the property. See also set(org.json.JSONObject)
      • set

        void set​(org.json.JSONObject properties)
        Set a collection of properties on the identified user all at once.
        Parameters:
        properties - a JSONObject containing the collection of properties you wish to apply to the identified user. Each key in the JSONObject will be associated with a property name, and the value of that key will be assigned to the property.
      • setOnce

        void setOnce​(java.lang.String propertyName,
                     java.lang.Object value)
        Works just like set(String, Object), except it will not overwrite existing property values. This is useful for properties like "First login date".
        Parameters:
        propertyName - The name of the Mixpanel property. This must be a String, for example "Zip Code"
        value - The value of the Mixpanel property. For "Zip Code", this value might be the String "90210"
      • setOnceMap

        void setOnceMap​(java.util.Map<java.lang.String,​java.lang.Object> properties)
        Like set(String, Object), but will not set properties that already exist on a record.
        Parameters:
        properties - a Map containing the collection of properties you wish to apply to the identified user. Each key in the Map will be associated with a property name, and the value of that key will be assigned to the property. See also setOnce(org.json.JSONObject)
      • setOnce

        void setOnce​(org.json.JSONObject properties)
        Like set(String, Object), but will not set properties that already exist on a record.
        Parameters:
        properties - a JSONObject containing the collection of properties you wish to apply to the identified user. Each key in the JSONObject will be associated with a property name, and the value of that key will be assigned to the property.
      • increment

        void increment​(java.lang.String name,
                       double increment)
        Add the given amount to an existing property on the identified user. If the user does not already have the associated property, the amount will be added to zero. To reduce a property, provide a negative number for the value.
        Parameters:
        name - the People Analytics property that should have its value changed
        increment - the amount to be added to the current value of the named property
        See Also:
        increment(Map)
      • merge

        void merge​(java.lang.String name,
                   org.json.JSONObject updates)
        Merge a given JSONObject into the object-valued property named name. If the user does not already have the associated property, an new property will be created with the value of the given updates. If the user already has a value for the given property, the updates will be merged into the existing value, with key/value pairs in updates taking precedence over existing key/value pairs where the keys are the same.
        Parameters:
        name - the People Analytics property that should have the update merged into it
        updates - a JSONObject with keys and values that will be merged into the property
      • increment

        void increment​(java.util.Map<java.lang.String,​? extends java.lang.Number> properties)
        Change the existing values of multiple People Analytics properties at once.

        If the user does not already have the associated property, the amount will be added to zero. To reduce a property, provide a negative number for the value.

        Parameters:
        properties - A map of String properties names to Long amounts. Each property associated with a name in the map will have its value changed by the given amount
        See Also:
        increment(String, double)
      • append

        void append​(java.lang.String name,
                    java.lang.Object value)
        Appends a value to a list-valued property. If the property does not currently exist, it will be created as a list of one element. If the property does exist and doesn't currently have a list value, the append will be ignored.
        Parameters:
        name - the People Analytics property that should have it's value appended to
        value - the new value that will appear at the end of the property's list
      • union

        void union​(java.lang.String name,
                   org.json.JSONArray value)
        Adds values to a list-valued property only if they are not already present in the list. If the property does not currently exist, it will be created with the given list as it's value. If the property exists and is not list-valued, the union will be ignored.
        Parameters:
        name - name of the list-valued property to set or modify
        value - an array of values to add to the property value if not already present
      • remove

        void remove​(java.lang.String name,
                    java.lang.Object value)
        Remove value from a list-valued property only if they are already present in the list. If the property does not currently exist, the remove will be ignored. If the property exists and is not list-valued, the remove will be ignored.
        Parameters:
        name - the People Analytics property that should have it's value removed from
        value - the value that will be removed from the property's list
      • unset

        void unset​(java.lang.String name)
        permanently removes the property with the given name from the user's profile
        Parameters:
        name - name of a property to unset
      • trackCharge

        void trackCharge​(double amount,
                         org.json.JSONObject properties)
        Track a revenue transaction for the identified people profile.
        Parameters:
        amount - the amount of money exchanged. Positive amounts represent purchases or income from the customer, negative amounts represent refunds or payments to the customer.
        properties - an optional collection of properties to associate with this transaction.
      • clearCharges

        void clearCharges()
        Permanently clear the whole transaction history for the identified people profile.
      • deleteUser

        void deleteUser()
        Permanently deletes the identified user's record from People Analytics.

        Calling deleteUser deletes an entire record completely. Any future calls to People Analytics using the same distinct id will create and store new values.

      • isIdentified

        boolean isIdentified()
        Checks if the people profile is identified or not.
        Returns:
        Whether the current user is identified or not.
      • setPushRegistrationId

        void setPushRegistrationId​(java.lang.String token)
        Manually send a Firebase Cloud Messaging token to Mixpanel.

        If you are handling Firebase Cloud Messages in your own application, but would like to allow Mixpanel to handle messages originating from Mixpanel campaigns, you should call setPushRegistrationId with the FCM token.

        setPushRegistrationId should only be called after identify(String) has been called. Optionally, applications that call setPushRegistrationId should also call clearPushRegistrationId() when they unregister the device id.

        Parameters:
        token - Firebase Cloud Messaging token
        See Also:
        clearPushRegistrationId()
      • clearPushRegistrationId

        void clearPushRegistrationId​(java.lang.String registrationId)
        Manually clear a single Firebase Cloud Messaging token from Mixpanel.

        clearPushRegistrationId() should only be called after identify(String) has been called.

        In general, all applications that call setPushRegistrationId(String) should include a call to clearPushRegistrationId.

        Parameters:
        registrationId - The device token you want to remove.
      • showNotificationIfAvailable

        void showNotificationIfAvailable​(android.app.Activity parent)
        Shows an in-app notification to the user if one is available. If the notification is a mini notification, this method will attach and remove a Fragment to parent. The lifecycle of the Fragment will be handled entirely by the Mixpanel library.

        If the notification is a takeover notification, a TakeoverInAppActivity will be launched to display the Takeover notification.

        It is safe to call this method any time you want to potentially display an in-app notification. This method will be a no-op if there is already an in-app notification being displayed.

        This method is a no-op in environments with Android API before JellyBean/API level 16.

        Parameters:
        parent - the Activity that the mini notification will be displayed in, or the Activity that will be used to launch TakeoverInAppActivity for the takeover notification.
      • joinExperimentIfAvailable

        void joinExperimentIfAvailable()
        Applies A/B test changes, if they are present. By default, your application will attempt to join available experiments any time an activity is resumed, but you can disable this automatic behavior by adding the following tag to the <application> tag in your AndroidManifest.xml <meta-data android:name="com.mixpanel.android.MPConfig.AutoShowMixpanelUpdates" android:value="false" /> If you disable AutoShowMixpanelUpdates, you'll need to call joinExperimentIfAvailable to join or clear existing experiments. If you want to display a loading screen or otherwise wait for experiments to load from the server before you apply them, you can use addOnMixpanelUpdatesReceivedListener(OnMixpanelUpdatesReceivedListener) to be informed that new experiments are ready.
      • showGivenNotification

        void showGivenNotification​(InAppNotification notif,
                                   android.app.Activity parent)
        Shows the given in-app notification to the user. Display will occur just as if the notification was shown via showNotificationIfAvailable. In most cases, it is easier and more efficient to use showNotificationIfAvailable.
        Parameters:
        notif - the InAppNotification to show
        parent - the Activity that the mini notification will be displayed in, or the Activity that will be used to launch TakeoverInAppActivity for the takeover notification.
      • trackNotification

        void trackNotification​(java.lang.String eventName,
                               InAppNotification notif,
                               org.json.JSONObject properties)
        Sends an event to Mixpanel that includes the automatic properties associated with the given notification. In most cases this is not required, unless you're not showing notifications using the library-provided in views and activities.
        Parameters:
        eventName - the name to use when the event is tracked.
        notif - the InAppNotification associated with the event you'd like to track.
        properties - additional properties to be tracked with the event.
      • getNotificationIfAvailable

        InAppNotification getNotificationIfAvailable()
        Returns an InAppNotification object if one is available and being held by the library, or null if no notification is currently available. Callers who want to display in-app notifications should call this method periodically. A given InAppNotification will be returned only once from this method, so callers should be ready to consume any non-null return value.

        This function will return quickly, and will not cause any communication with Mixpanel's servers, so it is safe to call this from the UI thread. Note: you must call call trackNotificationSeen(InAppNotification) or you will receive the same InAppNotification again the next time notifications are refreshed from Mixpanel's servers (on identify, or when your app is destroyed and re-created)

        Returns:
        an InAppNotification object if one is available, null otherwise.
      • showNotificationById

        void showNotificationById​(int id,
                                  android.app.Activity parent)
        Shows an in-app notification identified by id. The behavior of this is otherwise identical to showNotificationIfAvailable(Activity).
        Parameters:
        id - the id of the InAppNotification you wish to show.
        parent - the Activity that the mini notification will be displayed in, or the Activity that will be used to launch TakeoverInAppActivity for the takeover notification.
      • withIdentity

        MixpanelAPI.People withIdentity​(java.lang.String distinctId)
        Return an instance of Mixpanel people with a temporary distinct id. Instances returned by withIdentity will not check decide with the given distinctId.
        Parameters:
        distinctId - Unique identifier (distinct_id) that the people object will have
        Returns:
        An instance of MixpanelAPI.People with the specified distinct_id
      • addOnMixpanelUpdatesReceivedListener

        void addOnMixpanelUpdatesReceivedListener​(OnMixpanelUpdatesReceivedListener listener)
        Adds a new listener that will receive a callback when new updates from Mixpanel (like in-app notifications or A/B test experiments) are discovered. Most users of the library will not need this method since in-app notifications and experiments are applied automatically to your application by default.

        The given listener will be called when a new batch of updates is detected. Handlers should be prepared to handle the callback on an arbitrary thread.

        The listener will be called when new in-app notifications or experiments are detected as available. That means you wait to call showNotificationIfAvailable(Activity), and joinExperimentIfAvailable() to show content and updates that have been delivered to your app. (You can also call these functions whenever else you would like, they're inexpensive and will do nothing if no content is available.)

        Parameters:
        listener - the listener to add
      • removeOnMixpanelUpdatesReceivedListener

        void removeOnMixpanelUpdatesReceivedListener​(OnMixpanelUpdatesReceivedListener listener)
        Removes a listener previously registered with addOnMixpanelUpdatesReceivedListener.
        Parameters:
        listener - the listener to add
      • addOnMixpanelTweaksUpdatedListener

        void addOnMixpanelTweaksUpdatedListener​(OnMixpanelTweaksUpdatedListener listener)
        Sets the listener that will receive a callback when new Tweaks from Mixpanel are discovered. Most users of the library will not need this method, since Tweaks are applied automatically to your application by default.

        The given listener will be called when a new batch of Tweaks is applied. Handlers should be prepared to handle the callback on an arbitrary thread.

        The listener will be called when new Tweaks are detected as available. That means the listener will get called once joinExperimentIfAvailable() has successfully applied the changes.

        Parameters:
        listener - the listener to set
      • removeOnMixpanelTweaksUpdatedListener

        void removeOnMixpanelTweaksUpdatedListener​(OnMixpanelTweaksUpdatedListener listener)
        Removes the listener previously registered with addOnMixpanelTweaksUpdatedListener.
        Parameters:
        listener - Listener you that will be removed.