Pilgrim SDK allows geofencing around a configurable set of venues. Geofencess 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.
Why use geofences
For most use cases, regular Pilgrim SDK visit events are superior to geofencing. However, there are certain instances where geofencing is perferable.
- 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 than visiting.
- When you know a user is en route to a specific venue, and you want to know the second 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 three event types that are delivered directly to the client and through an optional webhook.
|entrance||Triggered on the first GPS signal that is received inside of the geofence.|
|dwell||Triggered after the user has “dwelled” within the geofence for a configurable length of time. Default is 1 minute.|
|exit||Triggered on the first GPS signal that is received outside of the geofence.|
To recieve geofence events on the client, add the event handler below:
Geofences will need to be set to a specific Foursquare venue, chain, or category (see below). For example, a partner could set up geofences for Foursquare HQ, all coffee shops, and all Chick-fil-a’s. A caveat here is that you cannot set up a geofence for an arbitrary lat/lng; this also means that some venue harmonization may need to take place beforehand if you already have a specific list of places you want to geofence. Geofences are set up globally across all users of the app.
A geofence event will contain the following:
|venue||Same as regular pilgrim venue object.|
|categoryIDs||Array of categoryIDs used by triggered geofence.|
|chainIDs||Array of chainIDs used by triggered geofence.|
|partnerVenueID||String of harmonized venueId.|
|location||Object containing location information about the geofence event.|
|timestamp||Unix/epoch timestamp in milliseconds of when the event occured.|
Geofences are 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.
CSV upload should contain a header row. Our importer will look for any of the headers below:
|name||A custom string that you can set to help you identify rules. Ex:
|venue_id||optional A single venue’s foursquare venue id. Ex:
|category_id||optional A comma separated list of Foursquare category ids.|
|chain_id||optional A comma separated list of Foursquare chain ids.|
|harmonized_venues||optional A boolean value to turn on geofences for all harmonized venues or none.|
|dwell_time||Dwell time (seconds) can be configured independently for each venue, category, or chain. Leaving dwell_time blank will default to using 1 minute (60 seconds) as a default, where the user will be required to get 2 location points inside the geofence for trigger event to fire.|
|radius||Defaults to 100 meters.|
name,venue_id,category_id,chain_id,harmonized_venues,dwell_time,radius "Test Single Venue","556f676fbd6a75a99038d8ec",,,,60,100 "Multiple Venues","556f676fbd6a75a99038d8ec,556f676fbd6a75a99038d8ec",,,,120,200
Note: One of venue_id, category_id, chain_id, or harmonized_venues 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.