Web messaging - clear local storage on browser close but not refresh/open new tab

Hi,

We are implementing custom web messaging with guest API. We ran into problem that the chat session and history persist after browser close, which is not what and we want.

May I ask is it possible to achieve:

  1. Clear local storage on browser close. so that it starts a new session.
  2. Keep the cookie and chat session across new tabs and on refresh.

We tried the onunload() function, but it cleared all cookies when the page refresh as well, so we are kinda stucked here.

Not sure if it is related to session storage. Any help is much appreciated.

Thank you,
Kelvin

hi,

if you put this function upon webmessaging started, eq something like this

Genesys("subscribe", "Messenger.opened", function(o){
var alldata =allStorage();
console.log('start gettting localstorage messenger opened');
console.log(alldata);
});

function allStorage() {
var values = [], keys = Object.keys(localStorage), i = keys.length;
while ( i-- ) {
values.push( keys[i] + ' -- '+ localStorage.getItem(keys[i]) );
}
return values;
}

you can see there are localstorage named ['....gcm......'], in my case,
_a879b436-694b-462a-9856-e2c6e1da7870:gcmcopn --> when user opening webmessaging
_a879b436-694b-462a-9856-e2c6e1da7870:gcmcsessionActive --> when user start put message/ start chatting

try to remove those localstorage upon browser closed, eq, use this javascript

window.onbeforeunload = function () {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
if(keys[i].indexOf('gcm')>0){
localStorage.removeItem(keys[i]);
}
}
}

then when user re-open new webmessaging browser, they will get clean webmessaging / refreshed. But still in PureCloud it continue to previous conversationId.

Thanks Fransiska! It worked perfectly. Only that new conversation is created in Genesys Cloud when clearing local storage, but we are fine with that.

Hello Kelvin :wave:
Indeed, asynchronous messaging brings the benefit of having continuous conversations, so that both end-user and brand can continue to exchange messages even when browser is closed.

Can you confirm which use-case you are trying to solve? (there might be more variations)

  1. Detect abandoned pages and disconnect corresponding conversation, or
  2. Clean-up web client for privacy reasons (this may be common for shared / public computers)

Hi Angelo,

I do understand persistant conversation is one of the benefit by messaging. But our clients are concerned about the user experience in shared device. In this case, we want to clean up the client after browser closed , but doing so will ruin the nature of messaging.

Do you have any ideas how to cater this specific use case?

Thanks,
Kelvin

Hi Kelvin, thanks for clarifying the use-case, which seems more around shared devices, which is a valid use-case and we will explore improvements. I've created this Idea for future evaluation: https://genesyscloud.ideas.aha.io/ideas/DXWMM-I-10
Ultimately, I think it's a tradeoff between maximum level of privacy vs. browser storage and data retention.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.