Mixpanel

Using Plot Projects and Mixpanel together allows you to segment your users based on the places they visit and add a location-intelligence layer to your marketing campaigns. You can, for example, segment and send push notifications to users whom you have qualified as 'Train Commuters’ based on who visited a train station more than eight times in the last week or 'Regular Cinema Visitors' based on who visited the cinema more than two times in the last month.

MixPanel goal

Set up a Listening Campaign in the Plot Projects dashboard

Plot Projects offers a Geo SDK that easily connects to the Mixpanel SDK (see paragraphs below). Once this is done you can create Listening Campaigns in the Plot Projects dashboard that track visits of your users.

The first step is to create the locations you want to track. This can be a single location like a train station:

Polygon

Or a large set of locations:

Multiple locations

Once your locations are set up, you can create a Plot Projects Listening Campaign defining the Segment you’d like users to be added after visiting the designated location(s).

When creating the campaign, set the field ‘Listening campaign Data’ with the tag key value in json format

{"key": "visited_train_station"}

Listening campaign

That’s it, you’ve finished setting up the location campaigns! Users can now be automatically added to the corresponding segments in your Mixpanel dashboard.

Plot Projects Listening Campaigns have many options, including:

  • Trigger on geofences, polygons and/or beacons.
  • Trigger on enter, exit or dwell.
  • Define opening hours per location.
  • Define start and end dates of the campaign.

Integrating into your app

Now that your Listening Campaign is set up, your app can be location-aware and forward the events to Mixpanel. This integration guide is designed for Android, but also works for other supported platforms of the Plot SDK. You can find iOS documentation here After completing the integration guide, when a user enters the Paddington Station Plot triggers a Mixpanel event. That results in the Mixpanel dashboard as below:

Mixpanel dashboard

Start with the Plot Projects integration guide and the Mixpanel integration guide. After integrating both libraries, you can forward geotrigger events from Plot Projects to Mixpanel.

To receive geotrigger events from Plot Projects, create a class that extends GeotriggerHandlerBroadcastReceiver. In that class you call the Mixpanel API in order to send the event.

public class MyGeotriggerHandlerBroadcastReceiver extends GeotriggerHandlerBroadcastReceiver {
   private static final String LOG_TAG = "MyGeotriggerHandler";
   private static final String PROJECT_TOKEN = "YOUR_PROJECT_TOKEN";

   @Override
   public List<Geotrigger> handleGeotriggers(List<Geotrigger> list) {
       MixpanelAPI mixpanel = MixpanelAPI.getInstance(getContext(), PROJECT_TOKEN);
       mixpanel.identify("1234"); // Identify the device, if haven't already done so
       for (Geotrigger geotrigger: list)
           try {
               JSONObject jsonObject = new JSONObject(geotrigger.getData());
               String key = jsonObject.getString("key");

               mixpanel.track(key);

               Log.d(LOG_TAG, "sent Mixpanel event: " + key);
           } catch (JSONException e) {
               // handle JSON exception
           }
       return list;
   }
}

The MyGeotriggerHandlerBroadcastReceiver, presented above, records an event for Mixpanel using the data field set in the dashboard as key.

To let Android find the receiver, add it to AndroidManifest.xml

<receiver
    android:name=".MyGeotriggerHandlerBroadcastReceiver"
    android:permission="false">
    <intent-filter>
        <action android:name="${applicationId}.plot.HandleGeotriggers" />
    </intent-filter>
</receiver>

What's next

Users are now added automatically to the corresponding segments in the Mixpanel dashboard. You can now target or create location-based marketing campaigns for these segments.