Migrating from v3
Batch Web SDK v4 is a major release, which introduces breaking changes from 3.x. This guide describes how to update the script in a website already using a previous version.
Upgrading the SDK version
To upgrade from v3 to v4, you need to change the SDK version in two places:
On your page script or tag manager, replace
https://via.batch.com/v3/bootstrap.min.js
withhttps://via.batch.com/v4/bootstrap.min.js
.Download the new SDK files and update your service worker implementation
If you're using
batchsdk-worker-loader.js
, simply replace this file with the new one.If you added Batch in your custom service worker implementation, set
BATCHSDK_MAJOR_VERSION
's value to4
.
Service worker configuration
This version introduced a new way of configuring your service worker implementation and especially if you need to specify a registration for a sub-scope that does not control the current page.
If you were using serviceWorkerPathOverride
, useExistingServiceWorker
or serviceWorkerTimeout
to integrate Batch with your own service worker (or uploading to a folder of your site), you will have to modify the Batch's SDK setup as following since this keys does not exist anymore.
When using registration
, Batch can't check that your Service Worker will properly work, your integration might break if your SW is not valid for push notifications.
For more information, please see the following sections :
Profile data collection
Data collection
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.
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 profile()
method. Let's see a migration example.
If you were previously doing something like that:
You should now do:
To see in details what's precisely changed since V3 please consult our changelog or visit the APIs Reference.
For more information, please see the following sections :
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 visit your website running on v4 :
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.
You may want to disable these migrations, to do so please update your Batch's SDK setup as following:
Event data
Batch Web SDK v4 introduced two new types of attribute that can be attached to an event : Array and Object.
We also took the liberty of updating the tracking event method.
What's change:
Optional
tag
attribute is no longer available and has been replaced by$tags
as reserved key under theattributes
object.Optional
label
attribute is no longer available and has been replaced by$label
as reserved key under theattributes
object.
So if you were previously doing something like:
You should now do:
For more information, please visit our custom event guide.
Last updated
Was this helpful?