Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start SDK from RN context #130

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Taylor123
Copy link

Applications built in React Native should have the ability to determine when Braze (aka Appboy) starts to collect information and count as an MAU. For our specific instance, we only want to store data for MAUs that have authenticated. To do so, we must only register the app with Braze when a user has authenticated.

This is a work in progress and currently only supports iOS. The approach for Android seems a bit less obvious as Braze is managed by the ActivityLifecycleCallbacks. Would appreciate the teams input on this ASAP as we'd like to reduce our current MAUs as we're not using the anon data.

One outstanding question:

  • Could there be any issues with storing push tokens with the change to the SDK lifecycle?

@Bucimis
Copy link
Collaborator

Bucimis commented Nov 9, 2021

@Taylor123 thank you for your efforts here. Thoughts:

  1. Do you anticipating initializing late for all app runs, or only initializing late the first time a user is identified (and on subsequent app runs, initializing in didFinishWithLaunching)? Proper handling of push depends on an Appboy instance being available while push delegates are being called, which is why we recommend initializing in didFinishWithLaunching in the normal case.
  2. Push tokens have similar issues as described above. When initializing late, you can eagerly flush the push token using [[Appboy sharedInstance] registerDeviceToken:deviceToken]; after initializing the SDK. However, if initializing late only once, you should get eventual consistency on push tokens with the standard integration.
  3. On Android, the way to initialize late would be to register the ActivityLifecycleCallbacks at the time you want to initialize late. You should also ensure you don't send push tokens to Braze for anonymous users, as receiving push can initialize the SDK.

Let us know a bit more about your expected use case for late initialization and we can give more specific guidance for 1-2

@Bucimis
Copy link
Collaborator

Bucimis commented Nov 10, 2021

@Taylor123 another workaround that should work:

  1. At app startup, if the user is not identified, disable the SDK.
  2. Once the user is identified, enable the SDK and initialize it
  3. On subsequent app startups, initialize the SDK normally (you will likely need to set a flag of some kind to do this)

@Taylor123
Copy link
Author

@Bucimis Would disabling work from RN since the JS context (and thus call to disable) is loaded after startWithApi is invoked?

@Bucimis
Copy link
Collaborator

Bucimis commented Nov 16, 2021

@Taylor123 true, unfortunately the initial disable call would need to take place in the native layer. Ultimately it may require the same amount of work as implementing late init without disable. The important part of any solution is that the call to startWithApikey in didFinishLaunching is gated until it's appropriate to call it (i.e. once the user has logged in).

@pang0018
Copy link

@Bucimis this sounds like a similar situation that our company is running into. We'd like to change the sdk configuration after a user is authenticated our system. That makes it hard to do since all the configuration is happening in the native layer on app initialization. Would it be possible to add react native methods to leverage what the iOS and Android SDKs already have to offer and allow configuration at run time from the javascript level?

For example:
https://www.braze.com/docs/developer_guide/platform_integration_guides/android/advanced_use_cases/runtime_configuration/

@Bucimis
Copy link
Collaborator

Bucimis commented Dec 3, 2021

@pang0018 thanks for the helpful context and feature request. Runtime configuration (and initialization) is something we're aiming to offer in the future across all SDKs. In the meantime, let us know if we can help you reach your intended use case with the existing API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants