Skip to main content

JAVA

Percept Java SDK

Getting Started

  1. Add the following lines to your package's pom.xml file to include the dependency:
<dependency>
<groupId>com.perceptinsight.sdk</groupId>
<artifactId>percept-sdk-java</artifactId>
<version>2.0</version>
</dependency>

Create Event


// 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);

Create User


// Create an user
UserProfile userProfile = new UserProfile("USR123")
.setName("Jane Smith")//optional
.setPhone("987-654-3210")//optional
.setEmail("[email protected]")//optional
.setDeviceToken("newDeviceToken456");//optional

// Capture the UserProfile
perceptAPI.captureUserProfile(userProfile);