// Instantiate a PerceptAPI object by initializing the token
PerceptAPI perceptAPI=new PerceptAPI.Builder("apiToken")
.connectTimeout(10)//Optional
.readTimeout(20)//Optional
.maxRetries(3)//Optional
.build();
// Event Builder for building events
EventBuilder eventBuilder = new EventBuilder();
// Create an event without properties
Event event=new Event("TestEvent")
.setUserId("USR123"); //Optional
// Capture the event
perceptAPI.capture(event);
// Create an EventCollection for batching events
EventCollection eventCollection = new EventCollection();
// Create properties for an event
JsonObject eventData = new JsonObject();
eventData.addProperty("attribute1", "value1");
eventData.addProperty("attribute2", "value2");
// Create an event with properties
Event eventWithProp = new Event("TestEvent2")
.setUserId("USR123")//optional
.setData(eventData);//optional
// Add the event with properties to the collection
eventCollection.addEvent(eventWithProp);
// Capture the entire event collection
perceptAPI.capture(eventCollection);