Skip to content
Menu

Concepts

Geofences

Markdown version

Add places in the console and get an event when someone with your app enters or leaves one, with the opt-in geofence module for iOS and Android. The SDK never asks for location permission and never sends the device's location.

SDK 0.7.0 and later. Not released yet.

A geofence is a circle around a place, such as a store. When someone with your app enters or leaves one, the SDK sends a track event, $geofence_enter or $geofence_exit. You use those events like any other: in segments, as an in-app message trigger, and in agent goals and targeting. There is no separate geofence campaign type.

How it protects privacy

  • The SDK never asks for location permission. Your app asks, with its own explanation, before it turns geofences on.
  • The SDK reads no location until your app calls enableGeofences().
  • The SDK downloads the app's whole geofence list. It never sends the device's location to Herald to find nearby places.
  • What reaches Herald is only the crossing: the geofence's id and name, as an event. The SDK sends no coordinates.
  • Geofences are a separate module. An app that doesn't add it never links CoreLocation (iOS) or Play Services location (Android).

1. Add geofences in the console

Open Settings, Geofences, with the app in view. Each geofence has a name, a latitude and longitude, and a radius from 100 meters to 10 kilometers. An app can have up to 100. Type the coordinates (copy them from any map app) and use Open in map to check the point. Only admins can add, change or delete geofences.

2. Add the module

Add the HeraldGeofence library product from the Herald Swift package to your app target, next to HeraldSDK.

swift
.product(name: "HeraldGeofence", package: "herald-ios"),

3. Get permission, then turn it on

Ask for background location in your app's own flow: "Always" on iOS (with NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription in Info.plist), and fine plus background location on Android 10 and later. Then call enableGeofences() after configure, at every launch, including when the system starts the app in the background for a crossing. On Android this is also what registers the geofences again after the phone restarts. Without the permission it logs a warning and does nothing.

swift
import HeraldGeofence

// In application(_:didFinishLaunchingWithOptions:), after Herald.configure, once the person granted Always:
Herald.shared.enableGeofences()

disableGeofences() stops monitoring until the next enableGeofences(). Call it when the person turns location features off in your app.

What the SDK monitors

iOSAndroid
HowCore Location region monitoringPlay Services GeofencingClient
How manyThe 20 nearest (Apple's limit, minus regions your app monitors itself)All of them: an app has at most 100, which is Google's limit
Picking the nearestBy distance to the edge, from the last known location, re-picked on significant location change when the app has more than fitNot needed
Already inside when it startsNo event until the person leaves and comes backSame
After a restart, or Location turned off and onKeeps monitoring: iOS keeps the regionsStops until the app next opens, which registers them again. Android drops an app's geofences on restart and when Location is turned off.

The SDK fetches the list at each enableGeofences() and keeps the last one on the device, so a launch without a network uses it. Changes in the console reach a device the next time the app starts.

The events

NameProperties
$geofence_entergeofence_id, geofence_name (strings)
$geofence_exitgeofence_id, geofence_name (strings)

The SDK sends at most one event per geofence and direction every 5 minutes, so a person walking along the edge doesn't send a burst. Crossings happen in the background, so they don't count as app activity (last active, active days or send-time checks). While the SDK is off (setEnabled(false) or wipeData()), crossings send nothing. At the next enableGeofences() or crossing, the SDK also stops monitoring and deletes the geofence data it kept on the device (the cached list and the last crossing times).

Turn it off for every device

Settings, SDK settings, Geofences: set it to Off and the SDK stops monitoring on every device the next time the app starts, even in apps that call enableGeofences(). Use app's value and On both leave it to the app.

Limits

  • Up to 100 geofences per app, each with a radius of 100 to 10,000 meters and a name of up to 100 characters.
  • Android: after the phone restarts, or Location is turned off and back on, geofences resume the next time the app opens. iOS keeps them.
  • iOS and Android decide when to report a crossing. It can take a few minutes, and small circles in places with few Wi-Fi networks or cell towers are less reliable. Apple and Google recommend a radius of at least 100 to 150 meters.
  • React Native, Flutter and Unity apps can use geofences from the native side of the app; the wrappers don't include them yet.

See Herald decide live →