Source: https://developers.woosmap.com/products/geofencing-sdk/ios-sdk/guides/monitor-user-visits/

> For clean Markdown of any page, append `.md` to the page URL.

> For a complete documentation index, see https://developers.woosmap.com/llms.txt

# Monitor user's Visits



Get the location and the time spent when a user is visiting places. These use cases are explained in
the [Visit and ZOI documentation](/products/geofencing-sdk/visits-zoi/).

## Collect user's Visits

### Set up for Visits monitoring

The first step in collecting Visits is to set `visitDelegate`, this should be done as early as possible in
your `didFinishLaunchingWithOptions` App Delegate. It is recommended to use the `visitsTracking` profile to monitor
visits and identify ZOI. You can also enable the `visitEnable` setting if you don't want to use a preset tracking
profile.

```swift
let dataVisit = DataVisit()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        // Set delegate of protocol Visit
        WoosmapGeofenceManager.shared.getLocationService().visitDelegate = dataVisit
        
        WoosmapGeofenceManager.shared.startTracking(configurationProfile: ConfigurationProfile.visitsTracking)
}
``` 

### Visit Service Delegate

In your class delegate, retrieve and delete Visit data: 

```swift
public class DataVisit:VisitServiceDelegate  {
    
    public init() {}

    public func processVisit(visit: Visit) {
        // this method is called when a visit is collected
    }
    
    public func readVisits()-> Array<Visit> {
        return Visits.getAll()
    }
    
    public func eraseVisits() {
        Visits.deleteAll()
    }
}
```

## Zone of Interest (ZOI)

### Set up for ZOI monitoring

ZOIs are built from visits, grouped by proximity. The Geofencing SDK implements the Fast Incremental Gaussian Mixture
Model of classification Algorithm [FIGMM](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0139931) to
build and update the ZOI according to visits recurrence over time.

For the ZOIs, in the app delegate, you can retrieve zoi data like this:

```swift
public class DataZOI {
    public init() {}
    
    public func readZOIs()-> [ZOI] {
        return ZOIs.getAll()
    }
    
    
    public func eraseZOIs() {
        ZOIs.deleteAll()
    }
}
```

Each ZOI includes the following information:

| Field name | Type     | Description                                                                                                                                            |
|------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `zoiId`      | UUID     | The unique identifier of the ZOI.                                                                                                                      |
| `idVisits`   | [UUID]   | The list of id visits included in this ZOI.                                                                                                            |
| `latMean`    | Double   | The latitude of the center of the ZOI (useful if you need to qualify the place of the visit with a search request over POIs or assets)                 |
| `lngMean`    | Double   | The longitude of the center of the ZOI (useful if you need to qualify the place of the visit with a search request over POIs or assets)                 |
| `startTime`  | DateTime | The entry date for the first ZOI visit.                                                                                                                |
| `endTime`    | DateTime | The exit date of the last ZOI visit                                                                                                                    |
| `duration`   | Int64    | The duration of all the accumulated visits of the ZOI                                                                                                  |
| `wktPolygon` | String   | This is the [Well-known text representation of geometry](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) of the ZOI polygon. |
