Package com.mixpanel.mixpanelapi
Class MixpanelAPI
- java.lang.Object
-
- com.mixpanel.mixpanelapi.MixpanelAPI
-
public class MixpanelAPI extends Object
Simple interface to the Mixpanel tracking API, intended for use in server-side applications. Users are encouraged to review our Javascript API for reporting user events in web applications, and our Android API for use in Android mobile applications. The Java API doesn't provide or assume any threading model, and is designed such that recording events and sending them can be easily separated.
-
-
Field Summary
Fields Modifier and Type Field Description protected StringmEventsEndpointprotected StringmGroupsEndpointprotected StringmPeopleEndpoint
-
Constructor Summary
Constructors Constructor Description MixpanelAPI()Constructs a MixpanelAPI object associated with the production, Mixpanel services.MixpanelAPI(String eventsEndpoint, String peopleEndpoint)Create a MixpaneAPI associated with custom URLS for events and people updates.MixpanelAPI(String eventsEndpoint, String peopleEndpoint, String groupsEndpoint)Create a MixpaneAPI associated with custom URLS for the Mixpanel service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeliver(ClientDelivery toSend)Sends a ClientDelivery full of messages to Mixpanel's servers.voiddeliver(ClientDelivery toSend, boolean useIpAddress)Attempts to send a given delivery to the Mixpanel servers.protected StringencodeDataString(String dataString)apply Base64 encoding followed by URL encodingvoidsendMessage(org.json.JSONObject message)Sends a single message to Mixpanel servers.
-
-
-
Constructor Detail
-
MixpanelAPI
public MixpanelAPI()
Constructs a MixpanelAPI object associated with the production, Mixpanel services.
-
MixpanelAPI
public MixpanelAPI(String eventsEndpoint, String peopleEndpoint)
Create a MixpaneAPI associated with custom URLS for events and people updates. Useful for testing and proxying. Most callers should use the constructor with no arguments.- Parameters:
eventsEndpoint- a URL that will accept Mixpanel events messagespeopleEndpoint- a URL that will accept Mixpanel people messages- See Also:
MixpanelAPI()
-
MixpanelAPI
public MixpanelAPI(String eventsEndpoint, String peopleEndpoint, String groupsEndpoint)
Create a MixpaneAPI associated with custom URLS for the Mixpanel service. Useful for testing and proxying. Most callers should use the constructor with no arguments.- Parameters:
eventsEndpoint- a URL that will accept Mixpanel events messagespeopleEndpoint- a URL that will accept Mixpanel people messagesgroupsEndpoint- a URL that will accept Mixpanel groups messages- See Also:
MixpanelAPI()
-
-
Method Detail
-
sendMessage
public void sendMessage(org.json.JSONObject message) throws MixpanelMessageException, IOExceptionSends a single message to Mixpanel servers. Each call to sendMessage results in a blocking call to remote Mixpanel servers. To send multiple messages at once, see #deliver(ClientDelivery)- Parameters:
message- A JSONObject formatted by #MessageBuilder- Throws:
MixpanelMessageException- if the given JSONObject is not (apparently) a Mixpanel message. This is a RuntimeException, callers should take care to submit only correctly formatted messages.IOException- if
-
deliver
public void deliver(ClientDelivery toSend) throws IOException
Sends a ClientDelivery full of messages to Mixpanel's servers. This call will block, possibly for a long time.- Parameters:
toSend-- Throws:
IOException- See Also:
ClientDelivery
-
deliver
public void deliver(ClientDelivery toSend, boolean useIpAddress) throws IOException
Attempts to send a given delivery to the Mixpanel servers. Will block, possibly on multiple server requests. For most applications, this method should be called in a separate thread or in a queue consumer.- Parameters:
toSend- a ClientDelivery containing a number of Mixpanel messages- Throws:
IOException- See Also:
ClientDelivery
-
encodeDataString
protected String encodeDataString(String dataString)
apply Base64 encoding followed by URL encoding- Parameters:
dataString- JSON formatted string- Returns:
- encoded string for data parameter in API call
- Throws:
NullPointerException- IfdataStringisnull
-
-