Skip to content

keenlabs/KeenClient-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Keen Java Client

Build Status

Use this library from any Java application where you want to record data using Keen IO.

API Documentation

Client Documentation

Installation

Just drop the jar we've created into your project and configure the project to use it. We recommend having a "libs" directory to contain external dependencies, but it's up to you.

Download the jar here.

Usage

To use this client with the Keen IO API, you have to configure your Keen IO Project ID and its access keys (if you need an account, sign up here - it's free).

Register Your Project ID and Access Keys
public void onInitialize() {
    // do other stuff...

    // initialize the Keen Client with your Project Token.
    KeenClient.initialize(KEEN_PROJECT_TOKEN);
}

The write key is required to send events to Keen IO - the read key is required to do analysis on Keen IO.

Send Events to Keen IO

Here’s a very basic example for an app that tracks "purchases":

protected void track() {
    // create an event to upload to Keen
    Map<String, Object> event = new HashMap<String, Object>();
    event.put("item", "golden widget");

    // add it to the "purchases" collection in your Keen Project
    try {
        KeenClient.client().addEvent("purchases", event);
    } catch (KeenException e) {
        // handle the exception in a way that makes sense to you
        e.printStackTrace();
    }
}
Do analysis with Keen IO
TODO
Generate a Scoped Key for Keen IO

Here's a simple method to generate a Scoped Write Key:

public String getScopedWriteKey(String apiKey) throws ScopedKeyException {
    Map<String, Object> options = new HashMap<String, Object>();
    options.put("allowed_operations", Arrays.asList("write"));
    return ScopedKeys.encrypt(apiKey, options);
}

That's it! After running your code, check your Keen IO Project to see the event has been added.

Changelog

1.0.3
  • Add Scoped Keys implementation.
1.0.2
  • Bugfix from 1.0.1 to actually use write key when adding events.
1.0.1
  • Changed project token -> project ID.
  • Added support for read and write scoped keys.

To Do

  • Support analysis APIs.

Questions & Support

If you have any questions, bugs, or suggestions, please report them via Github Issues. Or, come chat with us anytime at users.keen.io. We'd love to hear your feedback and ideas!

Contributing

This is an open source project and we love involvement from the community! Hit us up with pull requests and issues.

About

Official Java client for the Keen IO API. Build analytics features directly into your Java apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 17