Skip to content

FENCE-2607: Reduce Track Calls#527

Open
alanjcharles14 wants to merge 12 commits intomasterfrom
track-efficiency
Open

FENCE-2607: Reduce Track Calls#527
alanjcharles14 wants to merge 12 commits intomasterfrom
track-efficiency

Conversation

@alanjcharles14
Copy link
Contributor

Summary
Adds a new "efficient tracking" mode that reduces API calls by performing local state change detection on the device. When enabled, the SDK only makes /track API calls when it detects a geofence, place, or beacon entry/exit locally, significantly reducing network traffic and server load for users with many geofences.

New Features

New RadarTrackingOptions flags:

  • syncOnGeofenceEvents - Only sync when geofence entry/exit detected
  • syncOnPlaceEvents - Only sync when place entry/exit detected
  • syncOnBeaconEvents - Only sync when beacon entry/exit detected

New RadarEfficientTrackManager class that handles local state detection:

  • Caches nearby geofences, beacons, and places from server responses
  • Performs point-in-circle calculations to detect entries/exits locally
  • Maintains a "synced region" to know when cached data is still valid
  • Compares current detected state with last known server state

How It Works

  1. When a /track response returns, the SDK caches:
  • nearbyGeofences: Geofences near the user
  • nearbyBeacons: Beacons near the user
  • nearbyPlaces: Places near the user
  • syncedRegion: A circular region where the cached data is valid
  1. On subsequent location updates, if efficient tracking is enabled:
  • Check if user is still within the synced region
  • Perform local point-in-circle calculations to detect which geofences/beacons/places the user is inside
  • Compare with the last known state from the server
  • Only make a /track call if state has changed (entry or exit detected)
  1. If user moves outside the synced region, a /track call is always made to refresh cached data

Copilot AI review requested due to automatic review settings January 22, 2026 20:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request introduces an "efficient tracking" mode that reduces API calls by performing local state change detection for geofences, beacons, and places. When enabled via new tracking option flags, the SDK only makes /track API calls when it detects entry/exit events locally, significantly reducing network traffic.

Changes:

  • Adds three new boolean flags to RadarTrackingOptions: syncOnGeofenceEvents, syncOnPlaceEvents, and syncOnBeaconEvents
  • Implements RadarEfficientTrackManager class with local point-in-circle detection and state change comparison logic
  • Adds state persistence for nearby geofences, beacons, places, and a synced region to RadarState
  • Integrates efficient tracking checks into RadarLocationManager to conditionally skip /track API calls
  • Includes comprehensive unit tests for the new efficient tracking functionality

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
RadarSDK/Include/RadarTrackingOptions.h Added public API declarations for three new sync flags
RadarSDK/RadarTrackingOptions.m Implemented serialization, deserialization, and equality checks for new flags; initialized them to NO in all presets
RadarSDK/RadarEfficientTrackManager.h New header defining the efficient tracking manager interface with methods for state detection and location checks
RadarSDK/RadarEfficientTrackManager.m New implementation of local geofence/beacon/place detection using point-in-circle calculations and state comparison
RadarSDK/RadarState.h Added declarations for persisting nearby geofences, beacons, places, and synced region
RadarSDK/RadarState.m Implemented persistence methods for new cached data; fixed placeId type signature from array to string
RadarSDK/RadarLocationManager.h Exposed updateSyncedRegion method
RadarSDK/RadarLocationManager.m Integrated efficient tracking check before /track calls; added caching of nearby entities from API responses; implemented synced region calculation
RadarSDK/RadarUtils.h Changed import to full CoreLocation framework; added circular region serialization methods
RadarSDK/RadarUtils.m Implemented serialization/deserialization for CLCircularRegion
RadarSDK/RadarGeofence.m Added case-insensitive support for "Circle" geometry type
RadarSDKTests/RadarSDKTests.m Added 24 comprehensive unit tests covering efficient tracking scenarios
RadarSDK.xcodeproj/project.pbxproj Added new EfficientTrackManager files to build configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[self replaceSyncedGeofences:nearbyGeofences];
[self cacheNearbyEntitiesFromResponse:res];
}];
}];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just delete this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants