Product

Punching the clock with Radar + Segment + Slack

Earlier this month, we announced the Radar Segment Source beta. Segment customers can now send Radar Geofences, Insights, and Places events to hundreds of destinations like Amplitude, Redshift, and Slack.

To show how simple it is to use Radar + Segment, we built an app that posts to Slack when employees enter or exit the office. And we did it all in less than an hour.

The idea

Radar abstracts away the challenges and cross-platform differences of location context and tracking, allowing you to add location context and tracking to your app with just a few lines of code.

Radar has three context types: Geofences, Insights, and Places. In this case, because we know the location of our office, we'll use Geofences instead of Insights.

To build this app, we simply:

  1. Create a geofence in Radar
  2. Integrate the Radar SDK into our iOS or Android app
  3. Add Radar as a Segment source
  4. Add Slack as a Segment destination

1. Create a geofence in Radar

You can create Radar geofences via the dashboard, CSV import, or the API. In this case, we create a geofence via the dashboard.

On the New Geofences page, we search for a place or address, then customize the metadata and geometry of the geofence.

Looks good!

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_1.png

After signing up for Radar, this takes less than a minute.

2. Integrate the Radar SDK

We can integrate the Radar SDK into an iOS or Android app with just a few lines of code.

To integrate the SDK, we simply:

  • configure our project
  • import the SDK
  • initialize the SDK with our API key
  • identify the user (in this case, user ID = Slack username)
  • request location permissions
  • start background tracking

On iOS, our code looks like this:

import RadarSDK

// ...

@UIApplicationMain
class AppDelegate: UIApplicationDelegate {

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let publishableKey = Utils.getRadarPublishableKey()
    let userId = Utils.getSlackUsername()

    Radar.initialize(publishableKey: publishableKey)
    Radar.setUserId(userId)  
    Radar.requestAlwaysAuthorization()
    Radar.startTracking()

    return true
  }

}

On Android, our code looks like this:

import com.onradar.sdk.Radar;

// ...

public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String userId = Utils.getSlackUsername();

    Radar.initialize(this);
    Radar.setUserId(userId);
    Radar.requestPermissions(this);
    Radar.startTracking();
  }

}

That's it! Starting from an existing app, this takes only a few minutes.

3. Add Radar as a Segment source

In the Segment dashboard, we add Radar as a source and copy our write key:

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_3a.png

Then, in the Radar dashboard, we enable Segment on the Integrations page and paste our write key. Note that we can have separate write keys for development and production:

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_3b.png

We're done. By copying and pasting an API key, all of our Radar events are sent to Segment.

4. Add Slack as a Segment destination

Finally, in the Segment dashboard, we add Slack as a destination and connect it to the Radar source:

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_4a.png

In the destination settings, we can customize the Slack incoming webhook, channel, and message templates:

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_4b.png

Boom. Radar geofence entry and exit events are now posted to our Slack channel:

https://s3.amazonaws.com/io.radar.blog/posts/punching-the-clock-with-radar-segment-slack-abc196614b71/step_4c.png


With the Radar Segment Source beta, Segment customers can send Radar events not only to Slack, but also to hundreds of other destinations.

If you're a Segment customer and you want to integrate Radar, contact us! We'd love to help you get started.

It’s time to build

See what Radar’s location and geofencing
solutions can do for your business.