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?