Skip to contentSkip to navigationSkip to topbar
On this page
Looking for more inspiration?Visit the
(information)
You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.

Analytics Swift 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 using this plugin for Analytics-Swift(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", located in the upper left-hand corner.

Xcode

xcode page anchor

In the Xcode File menu, click Add Packages. You'll see a dialog where you can search for Swift packages. In the search field, enter the URL to this repo.

https://github.com/segment-integrations/analytics-swift-integrations-bugsnag

You'll then have the option to pin to a version, or specific branch, as well as which project in your workspace to add it to. Once you've made your selections, click the Add Package button.

Open your Package.swift file and add the following to your dependencies section:

1
.package(
2
name: "Segment",
3
url: "https://github.com/segment-integrations/analytics-swift-integrations-Bugsnag.git",
4
from: "1.0.0"
5
),

Using the Plugin in your App

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

Open the file where you setup and configure the Analytics-Swift library. Add this plugin to the list of imports.

1
import Segment
2
import SegmentBugsnag // <-- Add this line

Just under your Analytics-Swift library setup, call analytics.add(plugin: ...) to add an instance of the plugin to the Analytics timeline.

1
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
2
.flushAt(3)
3
.trackApplicationLifecycleEvents(true))
4
analytics.add(plugin: BugsnagDestination())

Your events will now be given to BugSnag session data and start flowing to BugSnag in Cloud Mode.


Once you've correctly set up your BugSnag integration, you should 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 moment to review the Identify Spec. An example Identify call looks like:

1
struct MyTraits: Codable {
2
let favoriteColor: String
3
}
4
5
analytics.identify(userId: "a user's id", MyTraits(favoriteColor: "fuscia"))

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 BugSnag's website(link takes you to an external page).