Auth0MetricsGuidesCustomer CommunicationLowcode

Tracking customer logins with Auth0

Auth0 is a low-code, drop-in solution to add authentication and authorization services to your applications. It’s an ideal platform to track user activity in Morning, especially login events. Note: this guide requires some code but we will provide all the snippets.

Configure the metric in Morning

To track user logins in Auth0 start by creating a “Logins” metric in Morning.

You’ll need to use the morning-js library to update the login metric. You can copy the Javascript code snippet from the metric to get started.

Now that the metric is configured in Morning, login to your Auth0 dashboard.

Configure the Flow in Auth0

In the Auth0 dashboard you’ll need to add a Login Flow.

In the editor that appears, select “Build Custom” in the Add Action section.

Then in the modal that appears select the default options and give the action a name:

Configure the custom action

An editor will appear. First you need to add the morning-js dependency.

• Name: morning-js • Version. Just leave this as the default “latest”.

Next add your Morning API key as a secret.

• Name: MORNING_API_KEY

• Value: This should be (an API key with write permissions from your Morning dashboard.). Note, this API key must have write permissions.

Now your action is ready to track user logins.

In the code editor, replace this section:

exports.onExecutePostLogin = async (event, api) => {
};

With this code snippet:

const { Morning } = require('morning-js');

exports.onExecutePostLogin = async (event, api) => {
  const morning = new Morning(event.secrets.MORNING_API_KEY);
  // Update our login metric
  await morning.metrics.increment('<YOUR_LOGIN_METRIC_ID>', 1, {
    email: event.user.email,
  });
};

Make sure to replace <YOUR_LOGIN_METRIC_ID> with the id of the metric that you just created in Morning.

Finally click “Deploy”

Apply the action

Once you’ve deployed your custom action, you’ll need to apply it to the login flow. Drag it from the “Add Action” sidebar into the login flow.

Then click “Apply”.

Confirm that it’s working

To make sure the connection is working correctly, just log in to your application and watch the metric in Morning. You should see the metric value update and the profiles appear.

This is a great metric to identify your most engaged customers or customers who haven’t been seen for a while. A login event is fundamentally a time when you have your customer’s attention. Maybe trigger a “hello” message or let them know that you’re happy to see them?

Customer Intelligence for Automations

Morning plugs into your existing workflows, automatically builds customer metrics, and lets you write data-driven automations for Zapier.

Get started for Free
Morning Characters