Using Webhooks with Mixpanel

A Mixpanel Webhook can act as a notification that will send a POST request to a URL as users meet pre-determined campaign criteria. The webhook will be sent to the specified URL containing a list of users that satisfy the campaign criteria.

Webhook targeting can be based on properties in user profiles, or events that did or did not occur within the last 90 days. For example, if you set a last login property, you can create a webhook that notifies you about users who haven't used your service for three weeks.

Creating a Webhook Campaign

Each webhook campaign requires a URL to post data to. To create a new webhook campaign, navigate to the Messages report and select Webhook from the "Create new message" dropdown. This will give you the following form:


Targeting Users

When you submit the form, it will ask you to define the targeting criteria for your message. For example, you can send a webhook that includes all users that haven't been tracked in over a week. You can use many combinations of profile properties when you're creating a real message.


Scheduling Your Webhook Campaign

Once you've targeted your users, you just have to schedule the webhook campaign. There are three options for scheduling campaigns:

  • ASAP messages: These messages are posted to your URL as soon as they match the targeting criteria. It's common for users to go from "not matching" to "matching" - many messages 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.
  • Scheduled messages: These messages can be set to go out at a specified time, day of week, and interval. For example, you could set your message to go out at 9am PST every Wednesday. When the message runs, it finds all the users who match the criteria you have defined (and who have not yet been reported to your endpoint for this set of criteria) and sends a post containing the associated users to your URL. The result is that you will receive a record for a given user no more than once for each scheduled message.
  • Recurring messages: These messages will be sent repeatedly to qualified users. Recurring Messages can be delivered daily, weekly, monthly, or “As criteria is met” (ASAP after users qualify for the message). Message limits give you additional control over the frequency and quantity of recurring Messages sent per user.

Receiving Webhook POSTS

A webhook is simply a remote HTTP endpoint that Mixpanel can POST data to when a new user matches the message criteria.

To receive a Mixpanel webhook, set up an endpoint on your web server exactly like you would for any other page that receives POST requests. We recommend you choose an endpoint that doesn't handle any other requests. Then specify this endpoint in Mixpanel during the message setup.

Mixpanel will send a POST request to the endpoint whenever the conditions of the message are satisfied. The POST request will be much like a standard POST request made from submitting an HTML form, with a content type of application/x‑www‑form‑urlencoded and a single parameter named users. The users parameter will contain a JSON list with data for up to 50 users. If there are more than 50 users that satisfy the message conditions, Mixpanel will batch these users up into sets of 50 and make a POST request for each batch.

Here's an example of the JSON we will send you:

         "Referring Domain":"",
         "$city":"Los Angeles",
         "Last Seen":"2012-11-20T15:26:17",
         "Referring URL":"",
         "Referring Domain":"",
         "$city":"Mountain View",
         "Last Seen":"2012-11-20T15:25:39",
         "Referring URL":"",

You must respond with a 200 OK HTTP response for Mixpanel to mark the users in the message as being successfully sent to the webhook. Otherwise, we will assume the webhook for the users in that POST request failed, and we will send them again in the next message attempt.

Testing Webhooks

When testing Mixpanel Webhooks through the Messages report, five profiles will be randomly selected from your project and delivered to the defined Webhook URL. You will want to make sure that your receiver does not inadvertently deliver these profiles as it would in production.

Is this article helpful?
3 out of 9 found this helpful



Article is closed for comments.

Articles in this section