Send Auth0 Events to Keen

Keen 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.

In this example, you will learn how to connect Auth0 to Keen and stream signup events. To implement this with Auth0, you just need to create one Rule in your pipeline.

Keen IO Dataflow

Record a sign-up event in Keen

Create a rule that will record user signup events for your apps in Keen. Please note:

  • In this example, we expect your Keen credentials to be stored in the global configuration object. Be sure to add your Write Key here before running your rule. Doing this allows you to use your key in multiple rules and prevents you from having to store it directly in the code.

  • For this rule, we send contextual information, such as IP address (can be used to deduce location), user ID, and username. However, you can send any number of properties.

  • For this rule, we track the event type using a persistent property called user.signedUp. When the property is set to true, we return immediately. Otherwise, we assume the event is a new signup, and if everything goes well, we set the property to true. The next time the user signs in, this rule will be skipped.

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);

Keep reading

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