Java

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

<dependency>
    <groupId>com.indicative.client.java</groupId>
    <artifactId>indicative-java</artifactId>
    <version>1.0.3</version>
</dependency>

Otherwise, download the client and add the Indicative.java 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:

Indicative.apiKey("Your-API-Key-Goes-Here");

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:

Indicative.event("Registration").uniqueId("user47")
        .addProperty("Gender","Female").addProperty("Age", 23)
        .done();

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 IndicativeTest.java file (located in /src/test/java/com/indicative/client/java).

Was this page helpful?