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 Localytics Plugin


Our Analytics-Swift Localytics Destination Plugin is open sourced on GitHub. Feel free to check it out here(link takes you to an external page).


Getting started

getting-started page anchor

Once the Segment library is integrated with your site or app, toggle Localytics on in your Segment destinations, and add your application's App Key, which you can find in your Localytics app settings. These new settings will take up to an hour to propogate to all of your existing users. For new users it'll be instanteneous.

If you are using version 1.3.0 or higher of the Segment-Localytics Android SDK, you can include a localytics.xml file in your Android project's res/values folder to define your settings. Note that any settings entered in the Segment UI will override the equivalent values defined in your localytics.xml file. You can read more about the localytics.xml file in Localytics's documentation here(link takes you to an external page).

To add the Localytics plugin to your app:

  1. From the Segment Destinations page click Add Destination.
  2. Search for Localytics and select it in the results that appear.
  3. Choose which source to connect to your Localytics destination.
  4. Add your Localytics App Key to the destination's settings tab.

(warning)

Warning

The Localytics library itself will be installed as an additional dependency.

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 for this repo:

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

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

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

1
.package(
2
name: "Segment",
3
url: "https://github.com/segment-integrations/analytics-swift-localytics.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 SegmentLocalytics // <-- 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: LocalyticsDestination())

Your events now have Localytics session data and start flowing to Localytics in device-mode.


When you make an Identify call, Segment sets the Localytics customerId and any special Localytics traits you provide, like name, email, or custom traits.


When you make a Track call, Segment logs an event with Localytics containing the name of the event and any optional event properties.