This SDK is for general Java applications. However, for Android, please see the android specific SDK.
This SDK is available through JitPack.
Add to pom.xml
:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.ht-sdks.events-sdk-java</groupId>
<artifactId>analytics</artifactId>
<version>LATEST</version>
</dependency>
- Add JitPack to your build
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add your dependendcy
compile 'com.github.ht-sdks.events-sdk-java:analytics:+'
Create an instance of the Analytics object:
import com.hightouch.analytics.Analytics;
public class Main {
public static void main(String... args) throws Exception {
final Analytics analytics =
Analytics.builder(WRITE_KEY)
.endpoint(API_ENDPOINT)
.build();
}
}
Some of the following examples use Guava’s immutable maps, but feel free to use plain old Java maps instead.
analytics.enqueue(TrackMessage.builder("Item Purchased")
.userId("f4ca124298")
.properties(ImmutableMap.builder()
.put("revenue", 39.95)
.put("shipping", "2-day")
.build()
)
);
analytics.enqueue(ScreenMessage.builder("Schedule")
.userId("f4ca124298")
.properties(ImmutableMap.builder()
.put("category", "Sports")
.put("path", "/sports/schedule")
.build()
)
);
analytics.enqueue(PageMessage.builder("Schedule")
.userId("f4ca124298")
.properties(ImmutableMap.builder()
.put("category", "Sports")
.put("path", "/sports/schedule")
.build()
)
);
Map<String, String> map = new HashMap();
map.put("name", "Michael Bolton");
map.put("email", "[email protected]");
analytics.enqueue(IdentifyMessage.builder()
.userId("f4ca124298")
.traits(map));
analytics.enqueue(GroupMessage.builder("some-group-id")
.userId("f4ca124298")
.traits(ImmutableMap.builder()
.put("name", "Segment")
.put("size", 50)
.build()
)
);
analytics.enqueue(AliasMessage.builder("previousId")
.userId("f4ca124298")
);
analytics.enqueue(TrackMessage.builder("Button Clicked")
.userId("f4ca124298")
.context(ImmutableMap.builder()
.put("ip", "12.212.12.49")
.put("language", "en-us")
.build()
)
);