Add this plugin to your applications to support both the Segment Analytics-Swift
SDK and the Braze Swift SDK.
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/braze-inc/braze-segment-swift
You'll then have the option to pin to a version, or specific branch, as well as select 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 do your the dependencies
section:
.package(
url: "https://github.com/braze-inc/braze-segment-swift",
from: "2.0.0"
),
Update your target dependencies to include either SegmentBraze
or SegmentBrazeUI
:
.target(
name: "...",
dependencies: [
.product(name: "Segment", package: "analytics-swift"),
.product(name: "SegmentBraze", package: "braze-segment-swift"),
]
),
Note:
SegmentBraze
does not provide any UI components and does not depend onBrazeUI
. If you need UI components, useSegmentBrazeUI
in place ofSegmentBraze
– but do not import both of them.
Open the file where you setup and configure the Analytics-Swift library. Add this plugin to the list of imports.
import Segment
import SegmentBraze // <-- Add this line, or replace with `import SegmentBrazeUI` if you need UI components
Just under your Analytics-Swift library setup, call analytics.add(plugin: ...)
to add an instance of the plugin to the Analytics timeline.
let analytics = Analytics(configuration: Configuration(writeKey: "<YOUR WRITE KEY>")
.flushAt(3)
.trackApplicationLifecycleEvents(true))
analytics.add(plugin: BrazeDestination())
Your events will now be given Braze session data and start flowing to Braze.
The BrazeDestination
initializer accepts two optional parameters allowing you more control over the SDK's behavior. For a full list of available configurations, refer to Braze.Configuration
.
BrazeDestination(
additionalConfiguration: { configuration in
// Configure the Braze SDK here, e.g.:
// - Debug / verbose logs
configuration.logger.level = .debug
// - Enable automatic push notifications support
configuration.push.automation = true
configuration.push.automation.requestAuthorizationAtLaunch = false
// - Enable universal link forwarding
configuration.forwardUniversalLinks = true
},
additionalSetup: { braze in
// Post initialization setup here (e.g. setting up delegates, subscriptions, keep a
// reference to the initialized Braze instance, etc.)
}
)
To enable push notifications support, refer to the Push Notifications documentation. To keep the integration minimal, the Braze SDK provides push automation features (see sample code above and the automation
documentation).
When making use of the IDFACollection
Segment plugin, the BrazeDestination
will automatically forward the collected IDFA to Braze.
If you have questions, please contact [email protected] or open a GitHub Issue.