If you’re integrating with a Maven project, just add the following dependency to your pom.xml file:

Otherwise, download the client and add the file (located in /src/main/java/com/indicative/client/java) to your project.

To start tracking events, first call the apiKey() method and pass in your API key, like so:

You should only have to do that once. Alternatively, you can hardcode the value of API_KEY at the top of the file. Once your API key is set, you can record events with a single line of code:
        .addProperty("Gender","Female").addProperty("Age", 23)
The static method event() takes the name of the event as a String argument. It returns a newly instantiated Event object. Note that all of the following methods (aside from done()) return the modified Event object, allowing them to be chained together as in the example.

Next, the uniqueId() method takes one String argument, which is the unique identifier associated with the user performing the action.

The addProperty() method takes two String arguments for the name and value of the property, respectively. This method is overloaded so that you can pass in int, long, float, double, and boolean property values without having to convert them to Strings yourself.

Finally, you must call done() to asynchronously post the event to our REST endpoint.

This client also includes several unit tests in the file (located in /src/test/java/com/indicative/client/java).


7 users found this helpful