AdvaitaADVAITA DOCS
GitHubGet started
Server SDKv1.0.0MIT License

Java SDK

com.acai:acai-java-sdk is the server-side Java SDK. It uses a thread-safe event queue with configurable retries and an optional middleware pipeline.

Installation

Gradle:

Groovy
implementation 'com.acai:acai-java-sdk:1.0.0'

Maven:

XML
<dependency>
<groupId>com.acai</groupId>
<artifactId>acai-java-sdk</artifactId>
<version>1.0.0</version>
</dependency>

Initialise

Java
import com.acai.Acai;
Acai client = Acai.getInstance();
client.init("YOUR_API_KEY");
client.setServerUrl("https://events.yourdomain.com/2/httpapi");
client.setEventUploadThreshold(10);
client.setEventUploadPeriodMillis(10_000);

For multiple isolated instances:

Java
Acai instance2 = Acai.getInstance("analytics");
instance2.init("OTHER_API_KEY");

Track events

Java
import com.acai.Event;
import org.json.JSONObject;
Event event = new Event("Purchase Completed", "user_abc123");
event.eventProperties = new JSONObject()
.put("product_id", "prod_123")
.put("price", 49.99)
.put("currency", "USD");
event.time = System.currentTimeMillis();
client.logEvent(event);
// With a result callback
client.logEvent(event, new AcaiCallbacks() {
public void onLogEventServerResponse(Event e, int status, String msg) {
System.out.println("Status: " + status);
}
});
client.flushEvents();

Identify users

Java
Event identifyEvent = new Event("$identify", "user_abc123");
identifyEvent.userProperties = new JSONObject()
.put("$set", new JSONObject()
.put("plan", "enterprise")
.put("company", "Acme Corp"))
.put("$setOnce", new JSONObject()
.put("first_seen", "2024-01-15"))
.put("$add", new JSONObject()
.put("login_count", 1));
client.logEvent(identifyEvent);

Config reference

MethodDefaultDescription
setServerUrl(url)https://your-acai-server.com/2/httpapiCollector endpoint.
useBatchMode(bool)falseUse the /batch endpoint.
setEventUploadThreshold(n)10Event count before flush.
setEventUploadPeriodMillis(ms)10000Time-based flush interval.
setLogMode(LogMode)ERROROFF · ERROR · WARN · DEBUG
setProxy(Proxy)Proxy.NO_PROXYCustom HTTPS proxy.
setCallbacks(cb)—Global event result callback.