Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Analytics Kotlin BugSnag Plugin


Bugsnag helps you detect and diagnose crashes in your application. Depending on the data you provide, Bugsnag can filter errors based on user name, user email, timeline, release stages, paying user status, and more. Add BugSnag tracking support to your applications via this plugin for Analytics-Kotlin(link takes you to an external page).


Getting started

getting-started page anchor
  1. From the Segment web app, click Catalog.
  2. Search for *"BugSnag in the Catalog, select it, and choose which of your sources to connect the destination to.
  3. Add your API key to your connection settings. You can find your API key in your Bugsnag dashboard under **Settings.

To install the Segment-bugsnag integration, add the following line to your gradle file:

implementation 'com.segment.analytics.kotlin.destinations:bugsnag:<latest_version>'

Or the following for Kotlin DSL:

implementation('com.segment.analytics.kotlin.destinations:bugsnag:<latest_version>')

Also add the BugSnag Gradle plugin dependency to your project level build.gradle.

1
buildscript {
2
dependencies {
3
// ...
4
classpath "com.bugsnag:bugsnag-android-gradle-plugin:7.4.1"
5
}
6
}

Or the following for Kotlin DSL:

1
buildscript {
2
dependencies {
3
// ...
4
classpath("com.bugsnag:bugsnag-android-gradle-plugin:7.4.1")
5
}
6
}

Using the plugin in your app

using-the-plugin-in-your-app page anchor

Open the file where you set up and configure the Analytics-Kotlin library. Add this plugin to the list of imports.

import com.segment.analytics.kotlin.destinations.bugsnag.BugsnagDestination

Under your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.

1
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
2
this.flushAt = 3
3
this.trackApplicationLifecycleEvents = true
4
}
5
analytics.add(plugin = BugsnagDestination())

Your events will now begin to flow to Bugsnag in device-mode.


Once you've set up your Bugsnag integration, identify each of your users as soon as you know their identity (this typically happens after log in or sign up), so that Bugsnag can provide you with more visibility into which user is encountering which error.

If you're not familiar with the Segment Specs, take a look to understand what the Identify method does. An example call would look like:

1
analytics.identify("user-123", buildJsonObject {
2
put("username", "MisterWhiskers")
3
put("email", "hello@test.com")
4
put("plan", "premium")
5
});

Bugsnag will show you the userId and traits in the Users tab of each error.


In addition to sending Bugsnag user-specific information, you can send handled exceptions and diagnostic data to your Bugsnag dashboard using Bugsnag's native methods. Documentation on these methods is available on their website(link takes you to an external page).