Git Product home page Git Product logo

braze-segment-swift's Introduction

Braze-Segment-Swift

Add this plugin to your applications to support both the Segment Analytics-Swift SDK and the Braze Swift SDK.

Adding the dependency

via Xcode

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.

via Package.swift

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 on BrazeUI. If you need UI components, use SegmentBrazeUI in place of SegmentBraze – but do not import both of them.

Using the Plugin in your App

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.

Additional Configuration

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.)
  }
)

Push Notifications Support

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).

⚠️ Important: Starting with analytics-swift 1.5.0, destination plugins are initialized asynchronously. In order for the Braze SDK to correctly handle push notifications, you must call the BrazeDestination.prepareForDelayedInitialization() method as early as possible in your app's lifecycle, in your application's AppDelegate.application(_:didFinishLaunchingWithOptions:) method.

IDFA Collection

When making use of the IDFACollection Segment plugin, the BrazeDestination will automatically forward the collected IDFA to Braze.

Questions?

If you have questions, please contact [email protected] or open a GitHub Issue.

braze-segment-swift's People

Contributors

bsneed avatar hokstuff avatar jerielng avatar lowip avatar michaelghseg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

braze-segment-swift's Issues

Run before and enrichment plugins in the BrazeDestination plugin (to enable debounce middleware)

Using the old SDK, we were advised to utilise this bit of middleware to avoid sending duplicate identify calls to Braze, which costs money. https://github.com/segmentio/segment-braze-mobile-middleware

There is no provided alternative that works with Segments new plugin system in the segment-swift package. I tried to manually implement this however the problem is as follows:

  • Segment runs adds its DestinationMetadataPlugin an enrichment step to its own SegmentDestination plugin
  • We want to run our middleware after that step, but before the BrazeDestination sends its event.
  • This should be easy as you can add before and enrichment plugins to a specific DestinationPlugin, however, the BrazeDestination plugin is not running any of the plugins added to it's timeline, as it provides a different implementation of execute(event:). See SegmentDestination for how they run timeline plugins before there own event code.

Do you have any advice on the best approach to implementing the debounce plugin? I suggest removing the execute(event:) implementation in BrazeDestination and using the default provided by Segment that runs the timeline middleware. The code for adding setting the IDFA on Braze can be moved to it's own plugin

Migration doubt

Hi!

We are currently migrating Braze to the Swift version, as well as the Segment plugin for Braze and I have a doubt: In the objC version of the library we had saveRemoteNotification as well as saveLaunchOptions to store any received userInfo while Braze was still uninitialized. I'm not seeing anything similar for the new destination plugin. How are we intended to proceed with this during the migration? what's your recommendation?

Thanks!

No way to set `triggerMinimumTimeInterval`

I don't see any possibility to set the triggerMinimumTimeInterval with Segment and this Braze integration. Both Analytics and BrazeDestination do not have this field in their api and the Braze instance within the destination is isolated. How is a Segment user supposed to access this?
The SEGAppboyIntegrationFactory used to allow settings the ABKMinimumTriggerTimeIntervalKey, is the access removal on purpose, is this a bug, or is there an undocumented way to do this?

Crash on iOS 17 Beta latest release

There is a crash on iOS when I integrate Braze with Segment. This happens when I open the app.

My code is below:

let configuration = Configuration(writeKey: apiKey)
            .trackApplicationLifecycleEvents(true)
            .flushAt(3)
            .flushInterval(10)
var analytics: Analytics? = nil
analytics?.add(plugin: BrazeDestination())

Crash Details Below

Thread 3 Queue : com.braze.http (serial)
#0	0x0000000109612c00 in closure #1 in static HTTP.Client.Plugin.modify(urlComponents:) ()
#1	0x000000010955b090 in partial apply for closure #1 in static HTTP.Client.Plugin.modify(urlComponents:) ()
#2	0x000000010955de7c in closure #1 in static HTTP.Client.Plugin.modify(urlComponents:)partial apply ()
#3	0x00000001095583f8 in specialized URLRequest.init<τ_0_0>(api:plugins:) ()
#4	0x000000010955a9f0 in specialized implicit closure #1 in HTTP.Client.innerPerform(_:extraPlugins:) ()
#5	0x000000010955cb04 in specialized thunk for @escaping @callee_guaranteed (@in_guaranteed τ_0_0, @guaranteed [HTTP.Client<τ_0_0>.Plugin]) -> (@out URLRequest, @error @owned Error) ()

Thread warning when adding destination

When adding the BrazeDestination to Segment via add(plugin: brazeDestination) and setting configuration.push.automation = true, I always get the warning:

Unable to perform push notification automation steps. The SDK will not be able to automatically process push notifications.
- reason: The SDK must be initialized on the main thread to enable push automation.

Wrapping the call in main dispatch or using MainActor does not change anything. Does the integration always dispatch the Braze initialisation to a background queue?

can I use Braze's "Automatic push integration" with "braze-segment-swift"?

OK, first I believe that the answer is already "no", but I'm looking for guidance on this...

the "braze-segment-swift" plugin instantiates its own "Braze" instance, after it receives configuration information from Segment.

But when I look at the Braze documentation, for setting up push notifications, it talks about doing it "automatically"
https://www.braze.com/docs/developer_guide/platform_integration_guides/swift/push_notifications/integration/#automatic-push-integration
But then there's this caveat:

The SDK must be initialized on the main thread to enable push notification automation. SDK initialization must happen before the application has finished launching or in your AppDelegate application(_:didFinishLaunchingWithOptions:) implementation

So, since Segment makes a web-service call to get all the configuration information, Braze get initialized by "braze-segment-swift" until after didFinishLaunchingWithOptions is called, right? So, does this mean that I need to use "Manual Push Integration"?

So, assuming that we need to to "Manual Push Integration", I was also wondering if there's guidance on handling a push-notification that launches the app from a Braze campaign. If we get it on launch, then "braze-segment-swift" will not have initialized Braze yet, so we'll need to pass this along at some point after Braze in instantiated, right?

I guess I'm asking for either guidance, or perhaps a more comprehensive sample app, that demonstates how one sets up Braze push notifications, while also using "braze-segment-swift"

Exact version missing.

Currently I am using SPM with rules set branch as main
Screen Shot 2022-09-28 at 3 51 41 pm

Instead above, I wanted to pin this dependency into my project with exact version.
Right now there is no release tag found in this repo.

Is there a version already or I am missing something here?
Please help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.