Available since version 2.0.0, Pilgrim SDK allows geofencing around a configurable set of venues or points. Geofences can be set for the venues, categories, or chains of your choosing. By default, Foursquare will use its knowledge of the venue’s location to return the right fence for a given place. You may also configure a radius of your choosing, but we recommend letting Pilgrim pick the right one to give you the optimal experience.
In SDK version 2.2.0, support for polygon shapes and arbitrary latitude/longitude points is also available. This allows greater customization and removes the reliance upon geofencing only Foursquare venue locations.
Why use Geofences
For use cases that rely on accuracy, regular Pilgrim SDK place visit detection is superior to geofencing. However, there are certain instances where geofencing is preferable:
When speed and proximity to a specific subset of venues is more important than accurately detecting visits there.
When it’s more important to know if a user is nearby a certain place rather than visiting.
When you want to track when users that are en-route to a specific venue, and you want to know as soon as they arrive.
Geofencing runs independently alongside regular Pilgrim SDK visit detection so you can still get the benefit of understanding everywhere your users go while enabling additional use cases.
Geofences have five potential event types that are delivered directly to the client and through an optional webhook:
Triggered on the first GPS signal that is received inside of the geofence.
Triggered after the user has “dwelled” within the geofence for a configurable length of time. Default is 1 minute.
Triggered when the device has dwelled inside a geofence radius and confirmed a stop at the venue within the radius. Only available in SDK versions 2.1.2 or greater
Triggered on the first GPS signal that is received outside of the geofence.
Triggered when the device is in a geofence radius during a get location request. Only available in SDK versions 2.1 or greater
To receive geofence events on the client, add the event handler below:
Geofences will need to be set to a specific Foursquare venue, chain, category or shape (see below). For example, a partner could set up geofences for Foursquare HQ, all coffee shops, and all Chick-fil-a’s. You can also set up a geofence for an arbitrary lat/lng or custom polygon shapes. For Foursquare venues, this means that some venue harmonization may need to take place beforehand if you already have a specific list of places you want to geofence.
Note: Geofences are set up globally across all users of the app. User specific geofences are not yet something we provide.
A geofence event will contain the following:
entrance, dwell, venueConfirmed, exit, or presence.
Same as regular pilgrim venue object.
Array of categoryIDs used by triggered geofence.
Array of chainIDs used by triggered geofence.
String of harmonized venueId.
Object containing location information about the geofence event.
Unix/epoch timestamp in milliseconds of when the event occured.
Geofences can be set up through a CSV upload in the Pilgrim developer console. If you want to geofence an entire chain or category of venues, you only need to upload the category or chain ID once and Foursquare will manage all of the geofences globally.
To manage geofences via API, please see our Geofence API docs.
CSV upload should contain a header row. Our importer will look for any of the headers below:
A custom string that you can set to help you identify rules. Ex: coffee shops or Polygon of park in NYC
A single venue’s Foursquare venue id. Ex: 556f676fbd6a75a99038d8ec
For arbitrary lat/lng: A single comma separated latitude and longitude pair. Ex: 37.7901332,-122.4088525 For polygons: A semi-colon separated list of at least 3 latitude and longitude pairs. Ex: 37.7901332,-122.4088525;...;37.7901332,-122.4088525 Note: When drawing polygons, make sure the first and last points match.
The number of minutes where the user will be required to get 2 location points inside the geofence for a “dwell” event to fire. Defaults to 1 minute.
The geofences’s radius in meters. Does not apply to polygon geofences. Minimum: 50 meters. Maximum: 5,000 meters. Defaults to 50 meters.
Note: One of venue_ids, category_ids, chain_ids or points is required.
If different dwell times are set for a matching venue, chain, and category (i.e., Starbucks venue, coffee category, Starbucks chain), the order of precedence is venue > chain > category.