react-native-branch-deep-linking-attribution
react-native-branch-deep-linking-attribution copied to clipboard
Make logging and IntegrationValidator available from RNBranchModule
Working with a React Native project currently focused on Android. We had some issues setting up Branch initially. Logging and the IntegrationValidator
would both have been useful in revealing our setup issues. We found those documented here for Branch's Android SDK:
https://help.branch.io/developers-hub/docs/android-testing
However, in a React Native project, the MainActivity
does not contain the Branch
module directly, it contains the RNBranchModule
. The documentation was already difficult to follow (where is IntegrationValidator
imported from?!), but translating these tools to React Native meant spending the better part of a day pouring over source code.
For those in a similar situation. I eventually came up with a workaround. I patched the file RNBranchModule.java
to add three lines.
First, I had to import IntegrationValidator.
/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/RNBranchModule.java:24
:
import io.branch.referral.validators.IntegrationValidator;
Then I added the logging and validator to the end of the initSession
method (which will eventually be called in the MainActivity
).
/node_modules/react-native-branch/android/src/main/java/io/branch/rnbranch/RNBranchModule.java:220
:
Branch.enableLogging();
IntegrationValidator.validate(reactActivity);
This worked, and allowed me to work through the setup issues I was having with our Branch setup. But it would be wonderful if in the future these methods were passed forward to RNBranchModule
(and documented in the RN docs), so the process of running them could be simplified.
Thanks @delventhalz!
a little bit faster without having to dive into Branch's code:
In your .java
file add
...
import io.branch.referral.Branch;
import io.branch.referral.validators.IntegrationValidator;
...
void fooBar() {
Branch.enableLogging();
IntegrationValidator.validate(reactActivity);
}
...