public class MessageBuilder extends Object
Constructor and Description |
---|
MessageBuilder(String token) |
Modifier and Type | Method and Description |
---|---|
org.json.JSONObject |
append(String distinctId,
org.json.JSONObject properties)
For each key and value in the properties argument, attempts to append
that value to a list associated with the key in the identified profile.
|
org.json.JSONObject |
append(String distinctId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
For each key and value in the properties argument, attempts to append
that value to a list associated with the key in the identified profile.
|
org.json.JSONObject |
delete(String distinctId)
Deletes the profile associated with the given distinctId.
|
org.json.JSONObject |
delete(String distinctId,
org.json.JSONObject modifiers)
Deletes the profile associated with the given distinctId.
|
org.json.JSONObject |
event(String distinctId,
String eventName,
org.json.JSONObject properties)
Creates a message tracking an event, for consumption by MixpanelAPI
See:
https://help.mixpanel.com/hc/en-us/articles/360000857366-Guide-to-Mixpanel-Basics
for a detailed discussion of event names, distinct ids, event properties, and how to use them
to get the most out of your metrics.
|
org.json.JSONObject |
groupDelete(String groupKey,
String groupId)
Deletes the group profile identified by the given groupKey and groupId.
|
org.json.JSONObject |
groupDelete(String groupKey,
String groupId,
org.json.JSONObject modifiers)
Deletes the group profile identified by the given groupKey and groupId.
|
org.json.JSONObject |
groupMessage(String groupKey,
String groupId,
String actionType,
Object properties,
org.json.JSONObject modifiers)
Formats a generic group profile message.
|
org.json.JSONObject |
groupRemove(String groupKey,
String groupId,
org.json.JSONObject properties)
For each key and value in the properties argument, attempts to remove
that value from a list associated with the key in the specified group profile.
|
org.json.JSONObject |
groupRemove(String groupKey,
String groupId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
For each key and value in the properties argument, attempts to remove
that value from a list associated with the key in the specified group profile.
|
org.json.JSONObject |
groupSet(String groupKey,
String groupId,
org.json.JSONObject properties)
Sets properties on the group profile identified by the given groupKey
and groupId, creating the profile if needed.
|
org.json.JSONObject |
groupSet(String groupKey,
String groupId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
Sets properties on the group profile identified by the given groupKey
and groupId, creating the profile if needed.
|
org.json.JSONObject |
groupSetOnce(String groupKey,
String groupId,
org.json.JSONObject properties)
Sets properties if they do not already exist on the group profile identified by the given groupKey
and groupId.
|
org.json.JSONObject |
groupSetOnce(String groupKey,
String groupId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
Sets properties if they do not already exist on the group profile identified by the given groupKey
and groupId.
|
org.json.JSONObject |
groupUnion(String groupKey,
String groupId,
Map<String,org.json.JSONArray> properties)
Merges list-valued properties into a group profile.
|
org.json.JSONObject |
groupUnion(String groupKey,
String groupId,
Map<String,org.json.JSONArray> properties,
org.json.JSONObject modifiers)
Merges list-valued properties into a group profile.
|
org.json.JSONObject |
groupUnset(String groupKey,
String groupId,
Collection<String> propertyNames)
Removes the properties named in propertyNames from the group profile identified by groupKey and groupId.
|
org.json.JSONObject |
groupUnset(String groupKey,
String groupId,
Collection<String> propertyNames,
org.json.JSONObject modifiers)
Removes the properties named in propertyNames from the group profile identified by groupKey and groupId.
|
org.json.JSONObject |
increment(String distinctId,
Map<String,Long> properties)
For each key and value in the properties argument, adds that amount
to the associated property in the profile with the given distinct id.
|
org.json.JSONObject |
increment(String distinctId,
Map<String,Long> properties,
org.json.JSONObject modifiers)
For each key and value in the properties argument, adds that amount
to the associated property in the profile with the given distinct id.
|
org.json.JSONObject |
peopleMessage(String distinctId,
String actionType,
Object properties,
org.json.JSONObject modifiers)
Formats a generic user profile message.
|
org.json.JSONObject |
remove(String distinctId,
org.json.JSONObject properties)
For each key and value in the properties argument, attempts to remove
that value from a list associated with the key in the specified user profile.
|
org.json.JSONObject |
remove(String distinctId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
For each key and value in the properties argument, attempts to remove
that value from a list associated with the key in the specified user profile.
|
org.json.JSONObject |
set(String distinctId,
org.json.JSONObject properties)
Sets a property on the profile associated with the given distinctId.
|
org.json.JSONObject |
set(String distinctId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
Sets a property on the profile associated with the given distinctId.
|
org.json.JSONObject |
setOnce(String distinctId,
org.json.JSONObject properties)
Sets a property on the profile associated with the given distinctId,
only if that property is not already set on the associated profile.
|
org.json.JSONObject |
setOnce(String distinctId,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
Sets a property on the profile associated with the given distinctId,
only if that property is not already set on the associated profile.
|
org.json.JSONObject |
trackCharge(String distinctId,
double amount,
org.json.JSONObject properties)
Tracks revenue associated with the given distinctId.
|
org.json.JSONObject |
trackCharge(String distinctId,
double amount,
org.json.JSONObject properties,
org.json.JSONObject modifiers)
Tracks revenue associated with the given distinctId.
|
org.json.JSONObject |
union(String distinctId,
Map<String,org.json.JSONArray> properties)
Merges list-valued properties into a user profile.
|
org.json.JSONObject |
union(String distinctId,
Map<String,org.json.JSONArray> properties,
org.json.JSONObject modifiers)
Merges list-valued properties into a user profile.
|
org.json.JSONObject |
unset(String distinctId,
Collection<String> propertyNames)
Removes the properties named in propertyNames from the profile identified by distinctId.
|
org.json.JSONObject |
unset(String distinctId,
Collection<String> propertyNames,
org.json.JSONObject modifiers)
Removes the properties named in propertyNames from the profile identified by distinctId.
|
public MessageBuilder(String token)
public org.json.JSONObject event(String distinctId, String eventName, org.json.JSONObject properties)
distinctId
- a string uniquely identifying the individual cause associated with this event
(for example, the user id of a signing-in user, or the hostname of a server)eventName
- a human readable name for the event, for example "Purchase", or "Threw Exception"properties
- a JSONObject associating properties with the event. These are useful
for reporting and segmentation of events. It is often useful not only to include
properties of the event itself (for example { 'Item Purchased' : 'Hat' } or
{ 'ExceptionType' : 'OutOfMemory' }), but also properties associated with the
identified user (for example { 'MemberSince' : '2012-01-10' } or { 'TotalMemory' : '10TB' })public org.json.JSONObject set(String distinctId, org.json.JSONObject properties)
JSONObject userProperties = new JSONObject();
userProperties.put("Company", "Uneeda Medical Supply");
userProperties.put("Easter Eggs", "Hatched");
JSONObject message = messageBuilder.set("12345", userProperties);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profile.public org.json.JSONObject set(String distinctId, org.json.JSONObject properties, org.json.JSONObject modifiers)
JSONObject userProperties = new JSONObject();
userProperties.put("Company", "Uneeda Medical Supply");
userProperties.put("Easter Eggs", "Hatched");
JSONObject message = messageBuilder.set("12345", userProperties);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profilemodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject setOnce(String distinctId, org.json.JSONObject properties)
JSONObject userProperties = new JSONObject();
userProperties.put("Date Began", "2014-08-16");
// "Date Began" will not be overwritten, but if it isn't already
// present it will be set when we send this message.
JSONObject message = messageBuilder.setOnce("12345", userProperties);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profilepublic org.json.JSONObject setOnce(String distinctId, org.json.JSONObject properties, org.json.JSONObject modifiers)
JSONObject userProperties = new JSONObject();
userProperties.put("Date Began", "2014-08-16");
// "Date Began" will not be overwritten, but if it isn't already
// present it will be set when we send this message.
JSONObject message = messageBuilder.setOnce("12345", userProperties);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profilemodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject delete(String distinctId)
JSONObject message = messageBuilder.delete("12345");
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to deletepublic org.json.JSONObject delete(String distinctId, org.json.JSONObject modifiers)
JSONObject message = messageBuilder.delete("12345");
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to deletemodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject increment(String distinctId, Map<String,Long> properties)
Map<String, Long> updates = new HashMap<String, Long>();
updates.put('Logins', 1);
JSONObject message = messageBuilder.set("12345", updates);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to change on the associated profile,
each associated with a numeric value.public org.json.JSONObject increment(String distinctId, Map<String,Long> properties, org.json.JSONObject modifiers)
Map<String, Long> updates = new HashMap<String, Long>();
updates.put('Logins', 1);
JSONObject message = messageBuilder.set("12345", updates);
mixpanelApi.sendMessage(message);
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- a collection of properties to change on the associated profile,
each associated with a numeric value.modifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject append(String distinctId, org.json.JSONObject properties)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the append operationpublic org.json.JSONObject append(String distinctId, org.json.JSONObject properties, org.json.JSONObject modifiers)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the append operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject remove(String distinctId, org.json.JSONObject properties)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the remove operationpublic org.json.JSONObject remove(String distinctId, org.json.JSONObject properties, org.json.JSONObject modifiers)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the remove operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject union(String distinctId, Map<String,org.json.JSONArray> properties)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the union operationpublic org.json.JSONObject union(String distinctId, Map<String,org.json.JSONArray> properties, org.json.JSONObject modifiers)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.properties
- properties for the union operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject unset(String distinctId, Collection<String> propertyNames)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.propertyNames
- properties for the unset operationpublic org.json.JSONObject unset(String distinctId, Collection<String> propertyNames, org.json.JSONObject modifiers)
distinctId
- a string uniquely identifying the profile to change,
for example, a user id of an app, or the hostname of a server. If no profile
exists for the given id, a new one will be created.propertyNames
- properties for the unset operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject trackCharge(String distinctId, double amount, org.json.JSONObject properties)
distinctId
- an identifier associated with a profileamount
- a double revenue amount. Positive amounts represent income for your business.properties
- can be null. If provided, a set of properties to associate with
the individual transaction.public org.json.JSONObject trackCharge(String distinctId, double amount, org.json.JSONObject properties, org.json.JSONObject modifiers)
distinctId
- an identifier associated with a profileamount
- a double revenue amount. Positive amounts represent income for your business.properties
- can be null. If provided, a set of properties to associate with
the individual transaction.modifiers
- can be null. If provided, the keys and values in the object will
be merged as modifiers associated with the update message (for example, "$time" or "$ignore_time")public org.json.JSONObject peopleMessage(String distinctId, String actionType, Object properties, org.json.JSONObject modifiers)
distinctId
- a string uniquely identifying the individual cause associated with this event
(for example, the user id of a signing-in user, or the hostname of a server)actionType
- a string associated in the HTTP api with the operation (for example, $set or $add)properties
- a payload of the operation. Will be converted to JSON, and should be of types
Boolean, Double, Integer, Long, String, JSONArray, JSONObject, the JSONObject.NULL object, or null.
NaN and negative/positive infinity will throw an IllegalArgumentExceptionmodifiers
- if provided, the keys and values in the modifiers object will
be merged as modifiers associated with the update message (for example, "$time" or "$ignore_time")IllegalArgumentException
- if properties is not intelligible as a JSONObject propertyset(String distinctId, JSONObject properties)
,
delete(String distinctId)
,
append(String distinctId, JSONObject properties, JSONObject modifiers)
public org.json.JSONObject groupSet(String groupKey, String groupId, org.json.JSONObject properties)
JSONObject groupProperties = new JSONObject();
groupProperties.put("$name", "Acme Incorporated");
groupProperties.put("Industry", "Manufacturing");
JSONObject message = messageBuilder.groupSet("company", "Acme Inc.", groupProperties);
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profile.public org.json.JSONObject groupSet(String groupKey, String groupId, org.json.JSONObject properties, org.json.JSONObject modifiers)
JSONObject groupProperties = new JSONObject();
groupProperties.put("$name", "Acme Incorporated");
groupProperties.put("Industry", "Manufacturing");
JSONObject message = messageBuilder.groupSet("company", "Acme Inc.", groupProperties);
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profile.modifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupSetOnce(String groupKey, String groupId, org.json.JSONObject properties)
JSONObject groupProperties = new JSONObject();
groupProperties.put("First Purchase", "Steel");
JSONObject message = messageBuilder.groupSetOnce("company", "Acme Inc.", groupProperties);
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profile.public org.json.JSONObject groupSetOnce(String groupKey, String groupId, org.json.JSONObject properties, org.json.JSONObject modifiers)
JSONObject groupProperties = new JSONObject();
groupProperties.put("First Purchase", "Steel");
JSONObject message = messageBuilder.groupSetOnce("company", "Acme Inc.", groupProperties);
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- a collection of properties to set on the associated profile. Each key
in the properties argument will be updated on on the profile.modifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupDelete(String groupKey, String groupId)
JSONObject message = messageBuilder.groupDelete("company", "Acme Inc.");
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific grouppublic org.json.JSONObject groupDelete(String groupKey, String groupId, org.json.JSONObject modifiers)
JSONObject message = messageBuilder.groupDelete("company", "Acme Inc.");
mixpanelApi.sendMessage(message);
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupRemove(String groupKey, String groupId, org.json.JSONObject properties)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- properties for the remove operationpublic org.json.JSONObject groupRemove(String groupKey, String groupId, org.json.JSONObject properties, org.json.JSONObject modifiers)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- properties for the remove operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupUnion(String groupKey, String groupId, Map<String,org.json.JSONArray> properties)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- properties for the union operationpublic org.json.JSONObject groupUnion(String groupKey, String groupId, Map<String,org.json.JSONArray> properties, org.json.JSONObject modifiers)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific groupproperties
- properties for the union operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupUnset(String groupKey, String groupId, Collection<String> propertyNames)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific grouppropertyNames
- properties for the unset operationpublic org.json.JSONObject groupUnset(String groupKey, String groupId, Collection<String> propertyNames, org.json.JSONObject modifiers)
groupKey
- the property that connects event data for Group AnalyticsgroupId
- the identifier for a specific grouppropertyNames
- properties for the unset operationmodifiers
- Modifiers associated with the update message. (for example "$time" or "$ignore_time").
this can be null- if non-null, the keys and values in the modifiers
object will be associated directly with the update.public org.json.JSONObject groupMessage(String groupKey, String groupId, String actionType, Object properties, org.json.JSONObject modifiers)
groupKey
- string identifier for the type of group, e.g. 'Company'groupId
- unique string identifier for the group, e.g. 'Acme Inc.'actionType
- a string associated in the HTTP api with the operation (for example, $set or $add)properties
- a payload of the operation. Will be converted to JSON, and should be of types
Boolean, Double, Integer, Long, String, JSONArray, JSONObject, the JSONObject.NULL object, or null.
NaN and negative/positive infinity will throw an IllegalArgumentExceptionmodifiers
- if provided, the keys and values in the modifiers object will
be merged as modifiers associated with the update message (for example, "$time" or "$ignore_time")IllegalArgumentException
- if properties is not intelligible as a JSONObject propertygroupSet(String groupKey, String groupId, JSONObject properties)
,
groupSetOnce(String groupKey, String groupId, JSONObject properties)
,
groupRemove(String groupKey, String groupId, JSONObject properties)
,
groupDelete(String groupKey, String groupId)
Copyright © 2019. All rights reserved.