A Java client of the ConvertLoop REST API. You can sign up for a ConvertLoop account at http://convertloop.co.
Add the dependency to your build.gradle
file:
dependencies {
compile 'co.convertloop:convertloop-java:0.1.0'
}
Add the dependency to your pom.xml
file:
<dependency>
<groupId>co.convertloop</groupId>
<artifactId>convertloop-java</artifactId>
<version>0.1.0</version>
</dependency>
Or download the JAR, its dependencies and include it in your project.
First, you need to create an instance of ConvertLoop class passing your appId and apiKey:
Convertloop convertloop = new Convertloop("appId", "apiKey", "v1")
You are now ready to start calling the API methods:
You need to pass at least one of the following: pid
, user_id
or email
to identify a user. Use pid
when you are updating a guest of your site (you can obtain this value from the cookie dp_pid
). Use user_id
to match the id
of the user in your application.
import java.util.HashMap;
Convertloop convertloop = new Convertloop("7aa23283", "wUDY7GN7m9P111Xj37sWhnuE", "v1");
HashMap<String, Object> person = new HashMap<String, Object>();
person.put("email", "alejo.escobar@convertloop.co");
person.put("first_name", "Alejandro");
person.put("last_name", "Escobar");
person.put("plan", "free");
convertloop.createOrUpdatePerson(person);
Any key different to pid
, user_id
, email
, first_seen_at
, last_seen_at
, add_to_segments
, and remove_from_segments
will be treated as a custom attribute of the person.
You can add or remove people from a segment ussing the add_to_segments
and remove_from_segments
keys:
import java.util.HashMap;
HashMap<String, Object> person = new HashMap<String, Object>();
person.put("email", "alejo.escobar@convertloop.co");
person.put("plan", "free");
person.put("add_to_segments", new String[] {"Learn Something"});
person.put("remove_from_segments", new String[] {"Lead"});
convertloop.createOrUpdate(person);
You can track an event for any person:
import java.util.HashMap;
HashMap<String, Object> person = new HashMap<String, Object>();
person.put("email", "alejo.escobar@convertloop.co");
HashMap<String, Object> metadata = new HashMap<String, Object>();
metadata.put("credits", 1000);
HashMap<String, Object> event = new HashMap<String, Object>();
event.put("name", "Billed");
event.put("person", person);
event.put("metadata", metadata);
event.put("occurred_at", new Date());
convertloop.sendEventLog(event);
If you don't specify the ocurred_at
key, the current time will be used. You can use the person
key to add custom attributes to that person, or add or remove that person to/from segments.