Geofencing: Track Enter and Exit Events on Mixpanel

Zak DeBrine
SpotSense
Published in
2 min readMay 5, 2019

This guide is for tracking enter and exit events from your SpotSense geofences and logging that data to Mixpanel. It is current as of May 4th, 2019.

This is a continuation of “How to create a geofence for your mobile app — Swift” Get up to speed by checking out that article here.

What you’ll need

  1. Segment account (free)
  2. Mixpanel account (free)
  3. SpotSense account (free)

1) Create a Segment account

https://segment.com/ > Sign up

2) Create a Mixpanel account

3) SpotSense SDK setup

4) Add SpotSense as a source in Segment

  • On your Segment dashboard, click “Add Source”
  • Search “Node JS” in the search-box > Click “Connect”
  • Give your Node JS source a name (We recommend naming it SpotSense) > Click “Add source”
  • Copy your write key for your SpotSense source
  • Go to your SpotSense dashboard and navigate to the “Integrations” tab > Paste your Segment write key > Click save

5) Add Mixpanel as a destination in Segment

  • Click on the gear icon in the top right corner of the Mixpanel dashboard > Click on your app under project settings.
  • At the bottom of the page under Access keys, Copy your Token
  • On your Segment Dashboard, click Add Destination
  • Choose Mixpanel as a destination
  • Paste your Token under the Mixpanel settings

6) Create your geofence > send enter and exit events to Segment

  • On SpotSense dashboard, click geofence > New geofence
  • Name your geofence
  • Draw geofence on map where you want to track enter and exit events
  • Disable notifications and send enter and exit events to Segment
  • Click create

7) Set up your mobile app on your device

  • Plug your iPhone into your machine
  • In Xcode, select the dropdown in the top left corner next to your app name > Choose your device
  • Run the app (This should start running the application on your phone)

8) Test the geofence, this should log enter and exit events to Mixpanel

There’s two ways you can test a geofence, by walking to the actual geofenced location, or testing it in the simulator. If you want to test it in the simulator, this video should give you everything you need.

  • When you trigger the geofence, you should see events like “geofenceName — Enter or “geofenceName — exit” Logged on your Mixpanel dashboard.
  • Congrats — You did it!
  • You can now leverage enter and exit events in Mixpanel just like you would any other event.
  • Use this same tactic to send geofence data to any destination on Segment

Let me know if this worked for you (it does for me!) and if you have any feedback.

--

--