Tutorial: Sending your first notification

It should only take a couple of minutes to send your first notification.

Install the Mixpanel JavaScript library

First, install a Mixpanel tracking library. In this example, we'll be using the JavaScript library, but there are many others (such as iOS and Android) for sending data from other platforms.

To install the library, just paste the following code into the <head> section of your HTML page. Make sure to change YOUR_TOKEN to your actual project token, which you can find by clicking your name in the upper righthand corner of your Mixpanel project and selecting Settings from the dropdown.

Create a profile

Mixpanel allows you to tie data to a specific user, creating a profile. This is where you store things like their email address, where they came from, or their age. When you include contact information, you can start sending targeted notifications right from Mixpanel.

In this example, we're going to set up a new email notification, so we need to create a profile with the "$email" property. Other types of notifications (such as iOS and Android push notifications) require different properties.

mixpanel.identify("13487");
mixpanel.people.set({
    "User name": "JoeDoe1980",
    "$first_name": "Joe",
    "$last_name": "Doe",
    "$email": "joe.doe@example.com"
});

Add your tracking code to the page and refresh to create the profile.

Look at your report

At this point, there should be a new record in your Explore report:

Create a notification

Move to the Notifications report and select "Email Message" in the "Create new notification" dropdown. You should see the following interface:

This interface should be largely self-explanatory, but it's important to note that you can use profile properties in all of the email fields.

Using profile properties in your email

Our templates will replace content that is wrapped in {{ }}. Here we're using the "User name" property we set before. In this case, we additionally wrap the property name in ${} to escape spaces.

Hey {{ ${User name} }},

Thanks for signing up. Need any help?

Target users

When you submit the form, it will ask you to define the targeting criteria for your notification. We're keeping it simple here and restricting the notification to the user we just created. You can use many combinations of profile properties when you're creating a real notification.

Schedule your email

Once you've targeted your users, you just have to schedule the email. There are two options for scheduling emails:

  • ASAP notifications: These notifications go out to individual users as soon as they match the targeting criteria for the first time. It's common for users to go from "not matching" to "matching" – many notifications include a time-based requirement such as "last login was greater than two weeks ago", or one based off of other profile properties that may change (Mixpanel will only send the notification to a user one time).
  • Scheduled notifications: These notifications can be set to go out at a specified time, day of week, or interval. For example, you could set your notification to go out at 9am PST every Wednesday. When the notification runs, it finds all the users who match the criteria you have defined (and who have never received this notification) and sends it to them.