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
 

Save a draft of your message at any time in this process by clicking the Save and Exit button at the bottom of the page.

Screen_Shot_2019-03-20_at_12.55.51_PM.png

You can view all of your saved drafts by clicking on the Drafts tab of the main Messages page.

Screen_Shot_2019-03-20_at_12.59.26_PM.png


Targeting Users

After submitting the form for your message design and content, you will then need to define the targeting criteria for the users who will receive the message.

A message's targeting criteria can contain one or more filters. Each filter can contain one or more conditions.

First, select an event, people property, or cohort from the first drop-down list.

MessagesTargetCriteria.png

You can add as many of these targeting filters as you like, which creates groups to target. Add more filters by clicking the + button.

You can then select whether you want to target customers that match all or only some of the filters you chose.

MessagesGroupUngroup.gif

Filtering by Events

If you select an event, you will be able to choose when or how frequently that event was performed or not performed by the users you are targeting.

MessagesTargetEvent.gif

You can filter deeper by event or people property by clicking the + Filter button.

You can also choose to add conditions to this targeting event by clicking the + Condition button in the top right of the group. This will serve as a second event target.

MessagesTargetEventCondition.png

You can then select whether you want your targeting users to do both the targeting event and the condition, either or, or to perform the targeting event and then the condition.

MessagesTargetConditionOrAndAll.png

Filtering by Property

If you select a people property, you will be able to choose the specifics of that property depending on the property type (date, string, list, etc.). For example, “First App Open” is a date property, so you will be able to choose when “First App Open” occurred.

MessagesTargetProperty.gif

You can select people property filters by clicking the + Filter button.

You can also choose to add one or more conditions to the property filter by clicking the + Condition button at the top right of the group. This will serve as a second property filter.

MessagesTargetPropertyCondition.png

You can then select whether you want your targeted users to have both the targeting property and the condition, or one or the other.

Filtering by Cohort

If you select a cohort, you will be able to select whether you want to target users in or not in the cohort.

MessagesTargetCohort.gif

You can select people property filters for that cohort by clicking the + Filter button.

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. You can't selectively choose the profile properties you want.

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. Mixpanel can take up to 3600 concurrent requests, and each request would have 50 users.

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?
6 out of 15 found this helpful

Comments

0 comments

Article is closed for comments.

Articles in this section