Documentation improvements
Thanks for your SDK, you are now the official way to use batch with React Native according the documentation 👏
Here is a few notes on my implementation, may be it will be useful for other people. In my project, I use dot env files, via react-native-config, to manage credentials per env. Here is my code :
.env file
BATCH_API_KEY_IOS=DEV******
BATCH_API_KEY_ANDROID=DEV*****
iOS side :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
//Batch SDK.
[BatchPush disableAutomaticIntegration];
NSString *batchApiKey = [ReactNativeConfig envFor:@"BATCH_API_KEY_IOS"];
#if DEBUG
NSLog(@"%@", batchApiKey);
#endif
[Batch startWithAPIKey:batchApiKey];
return YES;
}
Android side, app/build.gradle :
defaultConfig {
...
resValue "string", "BATCH_API_KEY", project.env.get("BATCH_API_KEY_ANDROID")
}
On the JS side, I connect the batch user with my user id
import { BatchPush, BatchUser, Batch } from '@bam.tech/react-native-batch';
BatchUser.editor()
.setIdentifier(user.id)
.save();
I also use batch to track some events
import { BatchUser, BatchEventData } from '@bam.tech/react-native-batch';
export function trackEvent(name: string, data?: any) {
const batchData = new BatchEventData();
if (data) {
Object.keys(data).forEach((key: Extract<keyof typeof data, string>) => {
batchData.put(key, data[key]);
});
}
BatchUser.trackEvent(name, undefined, batchData);
}
export function trackScreen(screenName: string) {
BatchUser.trackEvent('visited_screens', screenName);
}
Take care bamlab developers ❤️
Also, may be you could be more explicit about the SDK compatibility between RN and the batch SDKs Last RN Version : 0.61.5 Last Batch SDKs : 1.15.1
Thanks @padupuy for your contribution. I'm closing this issue as Batch released a new version and this repository is being archived.
This should be addressed in https://github.com/BatchLabs/Batch-React-Native-Plugin