When a user closes or reloads the chat page, JavaScript runs on the client
For example, you can use this Global action to clean the user's local storage and delete the cookies, when they close the browser chat page.
To set up this Global action:
- Add the Step name to the Set up Global Actions (RWC) Step.
- In the Step, turn on the Process chat close event (browser page close and refresh) toggle.
- In the Process as field, select JavaScript code from the dropdown.
- In the Code field, write the code in JavaScript.
NOTE
The chat will have only several milliseconds to execute this code on the client before closure.
- Save and activate the Flow.
Result
A user triggers script execution when they:
- close or reload the chat browser page
- close the RWC App
The JavaScript code is executed on the client, not in the Flow.
NOTE
This Global action does not get triggered when:
- a user closes the embedded RWC window
- a user clicks the Restart conversation button in the chat in case your chat has it
To delete or change this Global action further in the Flow
The Flow has the Set up Global Actions (RWC) Step that processes chat closure. If at a certain point in the conversation, you want to remove this Global action, override the Step. Add the second Set up Global Actions (RWC) Step below the first Step further in the Flow. The names of the two Steps can be different. In the second Step, to remove the logic of processing chat closure from the chat, disable the Process chat close event (browser page close and refresh) toggle. To change how this Global action is processed, edit the JavaScript.