Coexistence with 3rd party JS
Netcore CE Web SDK has the capablity to coexist with JS/SDKs of other vendors. This will help the client to not only send web push notifications from their platform / other vendor but also at the same time use Netcore CE for sending web push notifications.
For coexistence it is mandatory to put Netcore CE service worker along with client's/vendor's service worker in any case. Netcore CE supports only FCM and this holds true in case of Coexistence as well.
Netcore CE Web SDK Basic Setup is mandatory
After Netcore CE base SDK is integrated, Netcore CE will provide a Javascript method to get a combination of GUID, token and user identity (if exists). And it will also capture Tokens and all the events.
The first step to be taken for enabling coexistence is to
- Head over to the Asset section
- View/edit the integrated Website
- Enable Coexist.
Sending and Receiving Web Push tokens
There are 2 cases:
1.For Netcore CE to receive tokens
Client needs to add the following code snippet in their existing JS:
<script>
var token = TOKENVALUE;
smartech('set', 'token', token).then(function(response) {
console.log(response); // for debugging
//insert your business logic here
})
</script>
2.Netcore CE to send tokens,to 3rd party
The following code snippet is to be used :
<script>
smartech('get', 'token');
//ex
smartech('get', 'token').then(function(userToken) {
console.log(userToken); // for debugging
//insert your business logic here
})
</script>
Sending Web push notifications
There will be 2 cases for sending web push notifications
- The client will be sending WPN through Netcore CE
- The client will be sending WPN through 3rd party tool
Sending WPN though Netcore CE
While sending WPN from Netcore CE, we will introduce a new keyword 'origin = smartech' and then in our payload, we will check if this keyword exists with value or not. Then we will handle click, close, delivered events and take decisions whether to render WPN for the user from Netcore CE.
if the above-mentioned keyword doesn't exist, Netcore will ignore the push events and hence in such a case, the client will then be able to send WPN from their side along with the above-mentioned events.
Sending WPN though 3rd party
While sending WPN from 3rd party, the Client will check if keyword 'Origin = Smartech exists in the payload, with value or not.
if the above-mentioned keyword exists, the client will ignore the push events and hence in such a case, Netcore will then be able to send WPN from their side along with the above-mentioned events.
Implementation of Web Push Notification Events
To implement this feature following code snippet needs to be placed at client's sw.js to handle Web push notification events.
1. For push Event :
var pushOrigin = validatePushOrigin(notificationPayload);
if (pushOrigin === true) {
Promise.resolve();
return;
}
2. For notification click Event :
var pushOrigin = validatePushOrigin(notificationPayload);
if (pushOrigin === true) {
Promise.resolve();
event.notification.close();
return;
}
3. For notification close Event:
var pushOrigin = validatePushOrigin(notificationPayload);
if (pushOrigin === true) {
event.notification.close();
return;
}
4. Need to place below function in client's sw.js file to check the origin.
function validatePushOrigin(payload) {
if (payload.origin && payload.origin === 'smartech') {
return true;
}
return false;
}
5. To export token to Netcore CE platform following code needs to be added when user does opt-in activity on website.
/**
* This function will accept given token and will sent to Netcore CE platform
* @returns {promise}
*/
smartech('set','token', 'TOKENVALUE').then(function(response){
console.log(response);
//client's business logic will goes here if required
});
Updated 23 days ago