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:

Webhook1.png

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.

Webhook2.png 

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:

[
   {
      "$distinct_id":"13b20239a29335",
      "$properties":{
         "$region":"California",
         "$email":"harry.q.bovik@andrew.cmu.edu",
         "$last_name":"Bovik",
         "$created":"2012-11-20T15:26:16",
         "$country_code":"US",
         "$first_name":"Harry",
         "Referring Domain":"news.ycombinator.com",
         "$city":"Los Angeles",
         "Last Seen":"2012-11-20T15:26:17",
         "Referring URL":"http://news.ycombinator.com/",
         "$last_seen":"2012-11-20T15:26:19"
      }
   },
   {
      "$distinct_id":"13a00df8730412",
      "$properties":{
         "$region":"California",
         "$email":"anna.lytics@mixpanel.com",
         "$last_name":"Lytics",
         "$created":"2012-11-20T15:25:38",
         "$country_code":"US",
         "$first_name":"Anna",
         "Referring Domain":"www.quora.com",
         "$city":"Mountain View",
         "Last Seen":"2012-11-20T15:25:39",
         "Referring URL":"http://www.quora.com/What-...",
         "$last_seen":"2012-11-20T15:25:42"
      }
   }
]

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 6 found this helpful

Comments

0 comments

Article is closed for comments.

Articles in this section