public static interface MixpanelAPI.People
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();
}
}
MixpanelAPI| Modifier and Type | Method and 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)
|
void |
increment(java.util.Map<java.lang.String,? extends java.lang.Number> properties)
Change the existing values of multiple People Analytics properties at once.
|
void |
increment(java.lang.String name,
double increment)
Add the given amount to an existing property on the identified user.
|
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(org.json.JSONObject properties)
Set a collection of properties on the identified user all at once.
|
void |
set(java.lang.String propertyName,
java.lang.Object value)
Sets a single property with the given name and value for this user.
|
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(org.json.JSONObject properties)
Like
set(String, Object), but will not set properties that already exist on a record. |
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 |
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.
|
void identify(java.lang.String distinctId)
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.
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)MixpanelAPI.identify(String)void set(java.lang.String propertyName,
java.lang.Object value)
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"void setMap(java.util.Map<java.lang.String,java.lang.Object> properties)
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)void set(org.json.JSONObject properties)
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.void setOnce(java.lang.String propertyName,
java.lang.Object value)
set(String, Object), except it will not overwrite existing property values. This is useful for properties like "First login date".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"void setOnceMap(java.util.Map<java.lang.String,java.lang.Object> properties)
set(String, Object), but will not set properties that already exist on a record.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)void setOnce(org.json.JSONObject properties)
set(String, Object), but will not set properties that already exist on a record.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.void increment(java.lang.String name,
double increment)
name - the People Analytics property that should have its value changedincrement - the amount to be added to the current value of the named propertyincrement(Map)void merge(java.lang.String name,
org.json.JSONObject updates)
name - the People Analytics property that should have the update merged into itupdates - a JSONObject with keys and values that will be merged into the propertyvoid increment(java.util.Map<java.lang.String,? extends java.lang.Number> properties)
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.
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 amountincrement(String, double)void append(java.lang.String name,
java.lang.Object value)
name - the People Analytics property that should have it's value appended tovalue - the new value that will appear at the end of the property's listvoid union(java.lang.String name,
org.json.JSONArray value)
name - name of the list-valued property to set or modifyvalue - an array of values to add to the property value if not already presentvoid remove(java.lang.String name,
java.lang.Object value)
name - the People Analytics property that should have it's value removed fromvalue - the value that will be removed from the property's listvoid unset(java.lang.String name)
name - name of a property to unsetvoid trackCharge(double amount,
org.json.JSONObject properties)
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.void clearCharges()
void deleteUser()
Calling deleteUser deletes an entire record completely. Any future calls to People Analytics using the same distinct id will create and store new values.
boolean isIdentified()
java.lang.String getPushRegistrationId()
getPushRegistrationId() should only be called after identify(String) has been called.
setPushRegistrationId(String),
clearPushRegistrationId()void setPushRegistrationId(java.lang.String token)
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.
token - Firebase Cloud Messaging tokenclearPushRegistrationId()void clearPushRegistrationId()
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.
void clearPushRegistrationId(java.lang.String registrationId)
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.
registrationId - The device token you want to remove.java.lang.String getDistinctId()
set(String, Object) and increment(String, double).
If no calls to identify(String) have been made, this method will return null.
The id returned by getDistinctId is independent of the distinct id used to identify
any events sent with MixpanelAPI.track(String, JSONObject). To read and write that identifier,
use MixpanelAPI.identify(String) and MixpanelAPI.getDistinctId().
identify(String),
MixpanelAPI.getDistinctId()void showNotificationIfAvailable(android.app.Activity parent)
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.
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.void joinExperimentIfAvailable()
<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.void showGivenNotification(InAppNotification notif, android.app.Activity parent)
notif - the InAppNotification to showparent - the Activity that the mini notification will be displayed in, or the Activity
that will be used to launch TakeoverInAppActivity for the takeover notification.void trackNotification(java.lang.String eventName,
InAppNotification notif,
org.json.JSONObject properties)
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.InAppNotification getNotificationIfAvailable()
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)
void trackNotificationSeen(InAppNotification notif)
InAppNotification
in the case where you are manually dealing with your notifications (getNotificationIfAvailable()).
Note: if you do not acknowledge the notification you will receive it again each time
you call identify(String) and then call getNotificationIfAvailable()notif - the notification to track (no-op on null)void showNotificationById(int id,
android.app.Activity parent)
showNotificationIfAvailable(Activity).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.MixpanelAPI.People withIdentity(java.lang.String distinctId)
distinctId - Unique identifier (distinct_id) that the people object will haveMixpanelAPI.People with the specified distinct_idvoid addOnMixpanelUpdatesReceivedListener(OnMixpanelUpdatesReceivedListener listener)
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.)
listener - the listener to addvoid removeOnMixpanelUpdatesReceivedListener(OnMixpanelUpdatesReceivedListener listener)
listener - the listener to addvoid addOnMixpanelTweaksUpdatedListener(OnMixpanelTweaksUpdatedListener listener)
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.
listener - the listener to setvoid removeOnMixpanelTweaksUpdatedListener(OnMixpanelTweaksUpdatedListener listener)
listener - Listener you that will be removed.