Migrating from 5.0
Batch Cordova Plugin v6 is a major release based on natives SDK v2, which introduces breaking changes from 5.x. This guide describes how to update your application when using a previous version.
If you are still on the Batch Cordova Plugin v4, you should follow this guide beforehand.
Upgrading the SDK version
To upgrade from v5 to v6, you need to change the SDK version in your package.json
and run:
npm install
// or
yarn install
⚠️ Since this version is based on the Batch SDK 2.0, its now requires an Android minSdk
level of 21 or higher and iOS 13.0 or higher.
Core migration
Android - Push Providers
This version 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. If you are using cordova-plugin-firebase-messaging
, ensure it's based on firebase-messaging 22.0 or higher.
Advertising Identifier
Batch Cordova 5.4 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.
Advanced Information
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:
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)
});
Note: All data configurable with this API are now disabled by default and should be enabled if you want to use it.
For more information, please visit our automatic data collection guide.
Deprecated APIs
All deprecated APIs have been removed and some others have been renamed/reworked. To see in details the differences, please visit our changelog.
Project migration
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 this guide beforehand.
Profile Attributes
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:
batch.user.getEditor()
.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();
}
You should now do :
batch.profile.identify("john.doe");
batch.profile.getEditor()
.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();
}
For more information, please see the following sections :
Profile Data migration
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 update your sdk configuration setup as following :
batch.setConfig({
iOSAPIKey:"<YOUR_IOS_APIKEY>",
androidAPIKey:"<YOUR_ANDROID_APIKEY>",
migrations: {
// 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.
profileCustomIdMigrationEnabled: false,
// 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.
profileCustomDataMigrationEnabled: false,
}
});
batch.start();
For more information, please visit our profile data migration guide
Event data
Batch Cordova Plugin v6 introduced two new types of attribute that can be attached to an event : Array and Object.
What's change:
BatchEventData
has be renamed intoBatchEventAttributes
addTag
API is no longer available, you should now use the$tags
reserved key with theput
method.- Optional
label
parameter is no longer available and has been replaced by a$label
reserved key underBatchEventAttributes
.
Note: Limits are unchanged and still 200 chars max for $label and 10 items max for $tags .
So if you were previously doing something like:
const data = new batch.user.eventData();
data.addTag("squash");
data.addTag("daily_digest");
data.put("premium", true);
data.put("id", "123456");
batch.user.trackEvent("read_article", "sports", data);
You should now do:
const attributes = new batch.profile.eventAttributes()
attributes.put("premium", true)
.put("id", "123456")
.put("$label", "sports")
.put("$tags", ["squash", "daily_digest"]);
batch.profile.trackEvent("read_article", attributes);
For more information, please visit our custom event guide.
To see in details what's precisely changed since v5 please consult our changelog.