> ## Documentation Index
> Fetch the complete documentation index at: https://radarlabs-rob-onesignal-api-migration.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Segment

<Info>
  The Segment integration is available on the [**Enterprise plan**](https://radar.com/pricing).
</Info>

Radar can send events and user traits to [Segment](https://segment.com) as a source. Segment can send those events and user traits to your warehouse and to hundreds of destinations.

Use the Segment integration to forward location events and user context to any destinations or to build location-based user segments with Personas.

## Configuration

In Segment, add Radar as a source and copy your write key.

Then, on the Radar [Integrations page](https://dashboard.radar.com/integrations) under *Segment Source*, set *Enabled* to *Yes* and paste your write key. Note that you can set separate write keys for the *Test* and *Live* environments.

Whenever events are generated, Radar will call `track` and `identify` to send events and user traits to Segment.

By default, Radar `userId` maps to Segment `userId` for logged in users, and Radar `deviceId` maps to Segment `anonymousId` for logged out users. However, you can specify custom mappings by setting Radar `metadata.segmentUserId` or `metadata.segmentAnonymousId`. For example, on iOS:

```swift theme={null}
// track logged out users with custom anonymousId mapping (not required if using default mapping)
Radar.setMetadata(["segmentAnonymousId": anonymousId])

// track logged in users with custom userId mapping (not required if using default mapping)
Radar.setMetadata(["segmentUserId": userId])
```

## User mapping

Note that Radar uses the special string `"(null)"` to represent `null` user trait values.

| Radar User Field                            | Segment User Trait                            | Type           | Example Value                              | Context Type                       |
| ------------------------------------------- | --------------------------------------------- | -------------- | ------------------------------------------ | ---------------------------------- |
| `metadata.segmentUserId` or `userId`        | `userId`                                      | string         | `"1"`                                      |                                    |
| `metadata.segmentAnonymousId` or `deviceId` | `anonymousId`                                 | string         | `"10974a2ee035770b9"`                      |                                    |
| `_id`                                       | `radar_id`                                    | string         | `"5b2c0906f5874b001aecfd8d"`               |                                    |
| `location.coordinates[1]`                   | `radar_location_latitude`                     | number         | `39.525665`                                |                                    |
| `location.coordinates[0]`                   | `radar_location_longitude`                    | number         | `-76.350663`                               |                                    |
| `locationAuthorization`                     | `radar_location_authorization`                | string         | `"GRANTED_FOREGROUND"`                     |                                    |
| `locationAccuracyAuthorization`             | `radar_location_accuracy_authorization`       | string         | `"FULL"`                                   |                                    |
| `updatedAt`                                 | `radar_updated_at`                            | timestamp      | `"2018-06-22T15:23:39.000Z"`               |                                    |
| `segments[*].externalId`                    | `radar_segment_external_ids`                  | array\[string] | `["starbucks-visitors"]`                   |                                    |
| `topChains[*].slug`                         | `radar_top_chain_slugs`                       | array\[string] | `["starbucks", "walmart"]`                 |                                    |
| `topChains[*].externalId`                   | `radar_top_chain_external_ids`                | array\[string] | `["123", "456"]`                           |                                    |
| `geofences[*]._id`                          | `radar_geofence_ids`                          | array\[string] | `["5b2c0906f5874b001aecfd8e"]`             | [Geofences](/geofencing/geofences) |
| `geofences[*].description`                  | `radar_geofence_descriptions`                 | array\[string] | `["Store #123"]`                           | [Geofences](/geofencing/geofences) |
| `geofences[*].tag`                          | `radar_geofence_tags`                         | array\[string] | `["store"]`                                | [Geofences](/geofencing/geofences) |
| `geofences[*].externalId`                   | `radar_geofence_external_ids`                 | array\[string] | `["123"]`                                  | [Geofences](/geofencing/geofences) |
| `place._id`                                 | `radar_place_id`                              | string         | `"59302bcf8f27e8a156bd4f91"`               | [Places](/geofencing/places)       |
| `place.name`                                | `radar_place_name`                            | string         | `"Starbucks"`                              | [Places](/geofencing/places)       |
| `place.categories`                          | `radar_place_categories`                      | array\[string] | `["food-beverage", "cafe", "coffee-shop"]` | [Places](/geofencing/places)       |
| `place.chain.slug`                          | `radar_place_chain_slug`                      | string         | `"starbucks"`                              | [Places](/geofencing/places)       |
| `place.chain.name`                          | `radar_place_chain_name`                      | string         | `"Starbucks"`                              | [Places](/geofencing/places)       |
| `country.code`                              | `radar_region_country_code`                   | string         | `"US"`                                     | [Regions](/geofencing/regions)     |
| `country.name`                              | `radar_region_country_name`                   | string         | `"United States"`                          | [Regions](/geofencing/regions)     |
| `state.code`                                | `radar_region_state_code`                     | string         | `"MD"`                                     | [Regions](/geofencing/regions)     |
| `state.name`                                | `radar_region_state_name`                     | string         | `"Maryland"`                               | [Regions](/geofencing/regions)     |
| `dma.code`                                  | `radar_region_dma_code`                       | string         | `"26"`                                     | [Regions](/geofencing/regions)     |
| `dma.name`                                  | `radar_region_dma_name`                       | string         | `"Baltimore"`                              | [Regions](/geofencing/regions)     |
| `postalCode.code`                           | `radar_region_postal_code`                    | string         | `"21014"`                                  | [Regions](/geofencing/regions)     |
| `trip.externalId`                           | `radar_trip_external_id`                      | string         | `"299"`                                    | [Trip Tracking](/geofencing/trips) |
| `trip.destinationGeofenceTag`               | `radar_trip_destination_geofence_tag`         | string         | `"store"`                                  | [Trip Tracking](/geofencing/trips) |
| `trip.destinationGeofenceExternalId`        | `radar_trip_destination_geofence_external_id` | string         | `"123"`                                    | [Trip Tracking](/geofencing/trips) |
| `beacons[*]._id`                            | `radar_beacon_ids`                            | array\[string] | `["5b2c0906f5874b001aecfd8f]"`             | [Beacons](/geofencing/beacons)     |
| `beacons[*].description`                    | `radar_beacon_descriptions`                   | array\[string] | `["Store #123 - Drive-Thru"]`              | [Beacons](/geofencing/beacons)     |
| `beacons[*].tag`                            | `radar_beacon_tags`                           | array\[string] | `["drive-thru"]`                           | [Beacons](/geofencing/beacons)     |
| `beacons[*].externalId`                     | `radar_beacon_external_ids`                   | array\[string] | `["123"]`                                  | [Beacons](/geofencing/beacons)     |

## Event mapping

| Radar Event                         | Context Type                       | Segment Event                  |
| ----------------------------------- | ---------------------------------- | ------------------------------ |
| `user.entered_geofence`             | [Geofences](/geofencing/geofences) | `Geofence Entered`             |
| `user.exited_geofence`              | [Geofences](/geofencing/geofences) | `Geofence Exited`              |
| `user.dwelled_in_geofence`          | [Geofences](/geofencing/geofences) | `Dwelled in Geofence`          |
| `user.entered_place`                | [Places](/geofencing/places)       | `Place Entered`                |
| `user.exited_place`                 | [Places](/geofencing/places)       | `Place Exited`                 |
| `user.entered_region_country`       | [Regions](/geofencing/regions)     | `Country Entered`              |
| `user.exited_region_country`        | [Regions](/geofencing/regions)     | `Country Exited`               |
| `user.entered_region_state`         | [Regions](/geofencing/regions)     | `State Entered`                |
| `user.exited_region_state`          | [Regions](/geofencing/regions)     | `State Exited`                 |
| `user.entered_region_dma`           | [Regions](/geofencing/regions)     | `DMA Entered`                  |
| `user.exited_region_dma`            | [Regions](/geofencing/regions)     | `DMA Exited`                   |
| `user.started_trip`                 | [Trip Tracking](/geofencing/trips) | `Trip Started`                 |
| `user.updated_trip`                 | [Trip Tracking](/geofencing/trips) | `Trip Updated`                 |
| `user.approaching_trip_destination` | [Trip Tracking](/geofencing/trips) | `Trip Approaching Destination` |
| `user.arrived_at_trip_destination`  | [Trip Tracking](/geofencing/trips) | `Trip Arrived Destination`     |
| `user.stopped_trip`                 | [Trip Tracking](/geofencing/trips) | `Trip Stopped`                 |
| `user.entered_beacon`               | [Beacons](/geofencing/beacons)     | `Beacon Entered`               |
| `user.exited_beacon`                | [Beacons](/geofencing/beacons)     | `Beacon Exited`                |

### Geofence Entered

| Radar Event Field          | Segment Event Property    | Type    | Example Value                |
| -------------------------- | ------------------------- | ------- | ---------------------------- |
| `geofence._id`             | `geofence_id`             | string  | `"5b2c0906f5874b001aecfd8e"` |
| `geofence.description`     | `geofence_description`    | string  | `"Store #123"`               |
| `geofence.tag`             | `geofence_tag`            | string  | `"store"`                    |
| `geofence.externalId`      | `geofence_external_id`    | string  | `"123"`                      |
| `geofence.metadata[{key}]` | `geofence_metadata_{key}` | type    | `{value}`                    |
| `confidence`               | `confidence`              | string  | `"high"`                     |
| `foreground`               | `foreground`              | boolean | `true`                       |

### Geofence Exited

| Radar Event Field          | Segment Event Property    | Type             | Example Value                |
| -------------------------- | ------------------------- | ---------------- | ---------------------------- |
| `geofence._id`             | `geofence_id`             | string           | `"5b2c0906f5874b001aecfd8e"` |
| `geofence.description`     | `geofence_description`    | string           | `"Store #123"`               |
| `geofence.tag`             | `geofence_tag`            | string           | `"store"`                    |
| `geofence.externalId`      | `geofence_external_id`    | string           | `"123"`                      |
| `geofence.metadata[{key}]` | `geofence_metadata_{key}` | type             | `{value}`                    |
| `confidence`               | `confidence`              | string           | `"high"`                     |
| `duration`                 | `duration`                | number (minutes) | `42.1`                       |
| `foreground`               | `foreground`              | boolean          | `true`                       |

### Dwelled in Geofence

| Radar Event Field          | Segment Event Property    | Type             | Example Value                |
| -------------------------- | ------------------------- | ---------------- | ---------------------------- |
| `geofence._id`             | `geofence_id`             | string           | `"5b2c0906f5874b001aecfd8e"` |
| `geofence.description`     | `geofence_description`    | string           | `"Store #123"`               |
| `geofence.tag`             | `geofence_tag`            | string           | `"store"`                    |
| `geofence.externalId`      | `geofence_external_id`    | string           | `"123"`                      |
| `geofence.metadata[{key}]` | `geofence_metadata_{key}` | type             | `{value}`                    |
| `confidence`               | `confidence`              | string           | `"high"`                     |
| `duration`                 | `duration`                | number (minutes) | `42.1`                       |
| `foreground`               | `foreground`              | boolean          | `true`                       |

### Place Entered

| Radar Event Field             | Segment Event Property       | Type           | Example Value                              |
| ----------------------------- | ---------------------------- | -------------- | ------------------------------------------ |
| `place._id`                   | `place_id`                   | string         | `"59302bcf8f27e8a156bd4f91"`               |
| `place.name`                  | `place_name`                 | string         | `"Starbucks"`                              |
| `place.chain.slug`            | `place_chain_id`             | string         | `"starbucks"`                              |
| `place.chain.name`            | `place_chain_name`           | string         | `"Starbucks"`                              |
| `place.chain.metadata[{key}]` | `place_chain_metadata_{key}` | type           | `{value}`                                  |
| `place.categories`            | `place_categories`           | array\[string] | `["food-beverage", "cafe", "coffee-shop"]` |
| `confidence`                  | `confidence`                 | string         | `"high"`                                   |
| `foreground`                  | `foreground`                 | boolean        | `true`                                     |

### Place Exited

| Radar Event Field             | Segment Event Property       | Type             | Example Value                              |
| ----------------------------- | ---------------------------- | ---------------- | ------------------------------------------ |
| `place._id`                   | `place_id`                   | string           | `"59302bcf8f27e8a156bd4f91"`               |
| `place.name`                  | `place_name`                 | string           | `"Starbucks"`                              |
| `place.chain.slug`            | `place_chain_id`             | string           | `"starbucks"`                              |
| `place.chain.name`            | `place_chain_name`           | string           | `"Starbucks"`                              |
| `place.chain.metadata[{key}]` | `place_chain_metadata_{key}` | type             | `{value}`                                  |
| `place.categories`            | `place_categories`           | array\[string]   | `["food-beverage", "cafe", "coffee-shop"]` |
| `confidence`                  | `confidence`                 | string           | `"high"`                                   |
| `duration`                    | `duration`                   | number (minutes) | `42.1`                                     |
| `foreground`                  | `foreground`                 | boolean          | `true`                                     |

### Country Entered

| Radar Event Field | Segment Event Property | Type    | Example Value     |
| ----------------- | ---------------------- | ------- | ----------------- |
| `region.code`     | `region_code`          | string  | `"US"`            |
| `region.name`     | `region_name`          | string  | `"United States"` |
| `confidence`      | `confidence`           | string  | `"high"`          |
| `foreground`      | `foreground`           | boolean | `true`            |

### Country Exited

| Radar Event Field | Segment Event Property | Type    | Example Value     |
| ----------------- | ---------------------- | ------- | ----------------- |
| `region.code`     | `region_code`          | string  | `"US"`            |
| `region.name`     | `region_name`          | string  | `"United States"` |
| `confidence`      | `confidence`           | string  | `"high"`          |
| `foreground`      | `foreground`           | boolean | `true`            |

### State Entered

| Radar Event Field | Segment Event Property | Type    | Example Value |
| ----------------- | ---------------------- | ------- | ------------- |
| `region.code`     | `region_code`          | string  | `"MD"`        |
| `region.name`     | `region_name`          | string  | `"Maryland"`  |
| `confidence`      | `confidence`           | string  | `"high"`      |
| `foreground`      | `foreground`           | boolean | `true`        |

### State Exited

| Radar Event Field | Segment Event Property | Type    | Example Value |
| ----------------- | ---------------------- | ------- | ------------- |
| `region.code`     | `region_code`          | string  | `"MD"`        |
| `region.name`     | `region_name`          | string  | `"Maryland"`  |
| `confidence`      | `confidence`           | string  | `"high"`      |
| `foreground`      | `foreground`           | boolean | `true`        |

### DMA Entered

| Radar Event Field | Segment Event Property | Type    | Example Value |
| ----------------- | ---------------------- | ------- | ------------- |
| `region.code`     | `region_code`          | string  | `"26"`        |
| `region.name`     | `region_name`          | string  | `"Baltimore"` |
| `confidence`      | `confidence`           | string  | `"high"`      |
| `foreground`      | `foreground`           | boolean | `true`        |

### DMA Exited

| Radar Event Field | Segment Event Property | Type    | Example Value |
| ----------------- | ---------------------- | ------- | ------------- |
| `region.code`     | `region_code`          | string  | `"26"`        |
| `region.name`     | `region_name`          | string  | `"Baltimore"` |
| `confidence`      | `confidence`           | string  | `"high"`      |
| `foreground`      | `foreground`           | boolean | `true`        |

### Trip Started

| Radar Event Attribute                | Segment Event Property                  | Type    | Example Value |
| ------------------------------------ | --------------------------------------- | ------- | ------------- |
| `trip.externalId`                    | `trip_external_id`                      | string  | `"299"`       |
| `trip.metadata[{key}]`               | `trip_metadata_{key}`                   | type    | `{value}`     |
| `trip.destinationGeofenceTag`        | `trip_destination_geofence_tag`         | string  | `"store"`     |
| `trip.destinationGeofenceExternalId` | `trip_destination_geofence_external_id` | string  | `"123"`       |
| `foreground`                         | `foreground`                            | boolean | `true`        |

### Trip Updated

| Radar Event Attribute                | Segment Event Property                  | Type    | Example Value |
| ------------------------------------ | --------------------------------------- | ------- | ------------- |
| `trip.externalId`                    | `trip_external_id`                      | string  | `"299"`       |
| `trip.metadata[{key}]`               | `trip_metadata_{key}`                   | type    | `{value}`     |
| `trip.destinationGeofenceTag`        | `trip_destination_geofence_tag`         | string  | `"store"`     |
| `trip.destinationGeofenceExternalId` | `trip_destination_geofence_external_id` | string  | `"123"`       |
| `foreground`                         | `foreground`                            | boolean | `true`        |

### Trip Approaching Destination

| Radar Event Attribute                | Segment Event Property                  | Type    | Example Value |
| ------------------------------------ | --------------------------------------- | ------- | ------------- |
| `trip.externalId`                    | `trip_external_id`                      | string  | `"299"`       |
| `trip.metadata[{key}]`               | `trip_metadata_{key}`                   | type    | `{value}`     |
| `trip.destinationGeofenceTag`        | `trip_destination_geofence_tag`         | string  | `"store"`     |
| `trip.destinationGeofenceExternalId` | `trip_destination_geofence_external_id` | string  | `"123"`       |
| `foreground`                         | `foreground`                            | boolean | `true`        |

### Trip Arrived Destination

| Radar Event Attribute                | Segment Event Property                  | Type    | Example Value |
| ------------------------------------ | --------------------------------------- | ------- | ------------- |
| `trip.externalId`                    | `trip_external_id`                      | string  | `"299"`       |
| `trip.metadata[{key}]`               | `trip_metadata_{key}`                   | type    | `{value}`     |
| `trip.destinationGeofenceTag`        | `trip_destination_geofence_tag`         | string  | `"store"`     |
| `trip.destinationGeofenceExternalId` | `trip_destination_geofence_external_id` | string  | `"123"`       |
| `foreground`                         | `foreground`                            | boolean | `true`        |

### Trip Stopped

| Radar Event Attribute                | Segment Event Property                  | Type    | Example Value |
| ------------------------------------ | --------------------------------------- | ------- | ------------- |
| `trip.externalId`                    | `trip_external_id`                      | string  | `"299"`       |
| `trip.metadata[{key}]`               | `trip_metadata_{key}`                   | type    | `{value}`     |
| `trip.destinationGeofenceTag`        | `trip_destination_geofence_tag`         | string  | `"store"`     |
| `trip.destinationGeofenceExternalId` | `trip_destination_geofence_external_id` | string  | `"123"`       |
| `foreground`                         | `foreground`                            | boolean | `true`        |

### Beacon Entered

| Radar Event Attribute    | Segment Event Property  | Type    | Example Value                |
| ------------------------ | ----------------------- | ------- | ---------------------------- |
| `beacon._id`             | `beacon_id`             | string  | `"5b2c0906f5874b001aecfd8f"` |
| `beacon.description`     | `beacon_description`    | string  | `"Store #123 - Drive-Thru"`  |
| `beacon.tag`             | `beacon_tag`            | string  | `"drive-thru"`               |
| `beacon.externalId`      | `beacon_external_id`    | string  | `"123"`                      |
| `beacon.metadata[{key}]` | `beacon_metadata_{key}` | type    | `{value}`                    |
| `confidence`             | `confidence`            | string  | `"high"`                     |
| `foreground`             | `foreground`            | boolean | `true`                       |

### Beacon Exited

| Radar Event Attribute    | Segment Event Property  | Type             | Example Value                |
| ------------------------ | ----------------------- | ---------------- | ---------------------------- |
| `beacon._id`             | `beacon_id`             | string           | `"5b2c0906f5874b001aecfd8f"` |
| `beacon.description`     | `beacon_description`    | string           | `"Store #123 - Drive-Thru"`  |
| `beacon.tag`             | `beacon_tag`            | string           | `"drive-thru"`               |
| `beacon.externalId`      | `beacon_external_id`    | string           | `"123"`                      |
| `beacon.metadata[{key}]` | `beacon_metadata_{key}` | type             | `{value}`                    |
| `confidence`             | `confidence`            | string           | `"high"`                     |
| `duration`               | `duration`              | number (minutes) | `1.42`                       |
| `foreground`             | `foreground`            | boolean          | `true`                       |
