Upgrade from SDK V2 to V3
SDK V3 includes major improvements from V2. It is more stable and has better load performance.
Even though, the actual UI wasn't changed.
We can upgrade from V2 to V3 in a few steps:
1. Remove the old script.
Find and remove the following script tag of SDK v2 from your HTML file.
<script type="text/javascript" src="https://sdk-assets.anywhere.expert/production/v2/ae-sdk-loader.umd.js"></script>
2. Add the new snippet.
Add the snippet below at any place inside the code or HTML file - we highly suggest placing it in the HEAD
.
Make sure to replace APP_KEY_HERE
with your app key (in V2 the appkey is given in the initialize method).
<script>
(function () {
const w = window,
a = '__AE_SDK_ACTIONS',
d = document,
s = d.createElement('script', {}),
b = d.getElementsByTagName('script')[0];
w[a] = [];
w.AE_SDK = function (_) { w[a].push(_); };
s.type = 'text/javascript';
s.async = true;
s.defer = true;
s.src = 'https://assets.ae-sdk.io/core/v3?appKey=APP_KEY_HERE';
b.parentNode.insertBefore(s, b.nextSibling);
})();
</script>
3. Rewrite SDK V2 methods
First, using the SDK should no longer interact directly with the global object such as window.AE_SDK.<api-function-name>
.
Instead, following the usage guide, the API is through callbacks, for example:
window.AE_SDK(async (thrownError, AE_SDK_API) => {
// usages here, for example:
await AE_SDK_API.initialize();
await AE_SDK_API.auth.login();
});
The list below describes SDK V2 methods, and their replacement at V3 (assuming the usage is through the handler in the callback):
v2 method name | Replacement |
---|---|
initialize | initialize: the initialize method remains in V3, but without the appKey as first parameter. The app key moved to the install step and is given in the SDK URL. |
signOut | logout: AE_SDK.auth.logout(); |
anonymousSignIn | login: AE_SDK.auth.login(); |
signIn | login: AE_SDK.auth.login({ token }); |
show | using appendSettings to edit the settings, and set isHidden to false |
hide | using appendSettings to edit the settings, and set isHidden to true |
triggerMessagingOverlay | stays the same |
getAreExpertsAvailable | stays the same |
messagingApi.sendMessage | any previous sending message method is now being done with using sendMessage |
messagingApi.overrideExpertise | using appendSettings to edit the settings, and edit the expertise array |
messagingApi.overrideLanguageExpertise | using appendSettings to edit the settings, and edit the expertiseByTag object |
messagingApi.overrideMessagingPool | using appendSettings to edit the settings, and edit the messagingPool string |
attachSDKToContainer | using appendSettings to edit the settings, and set containerElementId |
registerNotificationToken | using setNotificationsToken |
registerApnsToken | using setNotificationsToken |