Sending events to Keen IO from Auth0

Keen IO provides a service to capture and analyze events generated in your apps. In their words:

Analytics transforms data into answers – the kind of answers every company deserves. Unfortunately, a lot of companies a) can't find an analytics service that's right for their specific needs, and b) don't have the resources to develop their own analytics infrastructure. That's why we started Keen IO. Basically, we built it, so you don't have to. And we made it powerful, flexible, and scalable enough that you can use it however you need to – even if those needs change over time.

This example shows how you can very easily connect Auth0 to Keen IO and stream signup events.

Implementing this with Auth0 is very easy, only taking a few lines of code.

Keen IO Dataflow

Recording a SignUp event in Keen IO

This rule checks whether the user has already signed up before or not. This is tracked by the user.signedUp property. If the property is present then we assume return immediately, otherwise we assume a new signup.

function(user, context, callback) {

    return callback(null, user, context);

  var writeKey = configuration.KEENIO_WRITE_KEY;
  var projectId = configuration.KEENIO_PROJECT_ID;
  var eventCollection = 'signups';

  var keenEvent = {
    userId: user.user_id,
    ip: context.request.ip //Potentially any other properties in the user profile/context
      method: 'POST',
      url: '' + projectId + '/events/' + eventCollection,
      headers: {
        "Authorization: " + writeKey,
        'Content-type': 'application/json'
      body: JSON.stringify(keenEvent),
      function (e, r, body) {
        if( e ) return callback(e,user,context);
        //We assume everything went well
        user.persistent.signedUp = true;
        return callback(null, user, context);

Notice that if all calls are successful, we signal the user as signed up. So next time we skip the entire rule.

Check out our repository of Auth0 Rules for more great examples: