Batch React-Native Plugin v9 is a major release based on natives SDK v2, which introduces breaking changes from 8.x. This guide describes how to update your application when using a previous version.
To upgrade from v8 to v9, you need to change the SDK version in your package.json and run:
yarn installnpm installIf you are using expo, don't forget to run the expo prebuild --clean command to rebuild the app with the plugin changes.
⚠️ Batch SDK 2.0 now requires a minSdk level of 21 or higher. If your application support lower Android versions, you will have to update it:
On iOS, update your target iOS minimum deployments version from Xcode if necessary.
The Batch React-Native plugin now automatically registers its own UNUserNotificationCenterDelegate and forwards it to the previous one if it exists.
This means you no longer need to add [BatchUNUserNotificationCenterDelegate registerAsDelegate] in your AppDelegate, please remove it or the plugin may not work as expected.
This version also removed support for old push providers (Google Cloud Messaging and FCM Instance ID). Batch now only support for FCM's Token APIs. Overriding the Sender ID is no longer possible in any way.
You have to use firebase-messaging 22.0.0 or higher. We highly recommend to use the latest version when possible.
Add the following to your build.gradle if not already present:
Batch React-Native 8.2 had removed automatic collection of AAID (Android Advertising Identifier) and IDFA (Identifier For Advertisers). This version has totally drop the support of the AAID and IDFA and you can no longer set an advertising id to Batch since all related APIs have been removed.
The natives Batch SDK V1 allowed you to disable advanced information generally with setCanUseAdvancedDeviceInformation(false) and setUseAdvancedDeviceInformation(false). This has been removed and replaced with a more fine-tuning control of what you want to enable directly in your js code with:
For more information, please visit our .
All deprecated APIs in the React-Native Plugin v8 have been removed and some others have been renamed/reworked. To see in details the differences, please visit our .
This version follows Batch's pivot to being an omnichannel platform. It allows you to collect data for your Projects and Profiles. If you are not familiar with these two concepts, please see beforehand.
First of all, most of the user-related write APIs have been removed. Reading methods are still usable since we do not provide yet a way to get synced data for a Profile, but keep in mind that the data returned is only about your installation and not your Profile.
To interacts with our user-centered model, you should now use the BatchProfile module. Let's see a migration example.
If you were previously doing something like that:
You should now do :
For more information, please see the following sections :
To make it easier to collect data to a Profile, Batch has added two automatic ways to migrate old installation's data on a Profile. So the first time a user will launch your application running on v9 :
He will be automatically identified (logged-in) if he had a Batch custom_user_id set on the local storage.
Its natives (language/region) and customs data will be automatically migrate to a Profile if your app is attached to a Project.
These migrations are enabled by default, but you may want to disable them, to do so add the following :
On Android, add the following meta-data tags to your AndroidManifest.xml:
On iOS, add the following entries to your Info.plist :
If you are using expo, please add the following keys to your app.json :
For more information, please visit our
React-Native Batch Plugin v9 introduced two new types of attribute that can be attached to an event : Array and Object.
What's change:
BatchEventData has be renamed into BatchEventAttributes
addTag API is no longer available, you should now use the $tags reserved key with the put method.
Optional label
So if you were previously doing something like:
You should now do:
For more information, please visit our .
To see in details what's precisely changed since V8 please consult our or visit the .
$labelBatchEventAttributesandroid {
...
defaultConfig {
...
minSdk = 21
}
}android {
...
defaultConfig {
...
minSdkVersion 21
}
}func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
RNBatch.start()
// Remove this line --> BatchUNUserNotificationCenterDelegate.registerAsDelegate()
return true
}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[RNBatch start];
// Remove this line --> [BatchUNUserNotificationCenterDelegate registerAsDelegate];
return YES;
}implementation("com.google.firebase:firebase-messaging:22.0.0")
// or if you are using firebase-bom
// val bom = platform("com.google.firebase:firebase-bom:28.0.0")
// implementation(bom)
// implementation("com.google.firebase:firebase-messaging")implementation 'com.google.firebase:firebase-messaging:22.0.0'
// or if you are using firebase-bom
// implementation platform('com.google.firebase:firebase-bom:28.0.0')
// implementation 'com.google.firebase:firebase-messaging'Batch.updateAutomaticDataCollection({
geoIP: true, // Enable GeoIP resolution on server side (optionnal - default: false)
deviceBrand: true, // Enable automatic collection of the device brand information (optionnal - default: false) (Android only)
deviceModel: true // Enable automatic collection of the device model information (optionnal - default: false)
});BatchUser.editor()
.setIdentifier("john.doe")
.setLanguage("en")
.setRegion("US")
.setEmail("john.doe@batch.com")
.setEmailMarketingSubscriptionState(BatchEmailSubscriptionState.SUBSCRIBED)
.setAttribute("age", 26)
.removeAttribute("firstname")
.addTag("actions", "has_bought")
.removeTag("actions", "has_bought")
.clearTagCollection("actions")
.save();
}BatchProfile.identify("john.doe");
BatchProfile.editor()
.setLanguage("en")
.setRegion("US")
.setEmailAddress("john.doe@batch.com")
.setEmailMarketingSubscription(BatchEmailSubscriptionState.SUBSCRIBED)
.setAttribute("age", 26)
.removeAttribute("firstname")
.addToArray("actions", "has_bought") // or addToArray("actions", ["has_bought"])
.removeFromArray("actions", "has_bought") // or removeFromArray("actions", ["has_bought"])
.removeAttribute("actions")
.save();
}<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:name=".MainApplication"...>
<!-- Whether Batch should automatically identify logged-in user when running the SDK for the first time.-->
<!-- This mean user with a custom_user_id will be automatically attached a to a Profile and could be targeted within a Project scope.-->
<meta-data android:name="batch.profile_custom_id_migration_enabled" android:value="true"/>
<!-- Whether Batch should automatically attach current installation's data (language/region/customDataAttributes...)-->
<!-- to the User's Profile when running the SDK for the first time.-->
<meta-data android:name="batch.profile_custom_data_migration_enabled" android:value="true"/>
...
</application>
</manifest><plist version="1.0">
<dict>
...
<key>BatchProfileCustomDataMigrationEnabled</key>
<true/>
<key>BatchProfileCustomIdMigrationEnabled</key>
<true/>
</dict>
</plist>// app.json/app.config.js
{
"expo": {
...,
"plugins": [
[
"@batch.com/react-native-plugin", {
"androidApiKey": "YOUR_ANDROID_BATCH_API_KEY",
"iosApiKey": "YOUR_IOS_BATCH_API_KEY",
"enableProfileCustomIDMigration": false,
"enableProfileCustomDataMigration": false
}
]
]
}
}const data = new BatchEventData();
data.addTag("squash");
data.addTag("daily_digest");
data.put("premium", true);
data.put("id", "123456");
BatchUser.trackEvent("read_article", "sports", data); const attributes = new BatchEventAttributes();
attributes.put("premium", true)
.put("id", "123456")
.put("$label", "sports")
.put("$tags", ["squash", "daily_digest"]);
BatchProfile.trackEvent("read_article", attributes);