Hi everyone,
I am using the lifecycle api from the client app sdk https://developer.mypurecloud.com/api/client-apps/sdk/LifecycleApi.html
The goal is to catch an event when the user leaves the app so that I can keep track of the users that are using the solution. I already configured the app to opt in the different hooks (stop, blur, focus). I am able to catch blur & focus events but I never see the stop event being triggered.
Integration advanced config:
{
"lifecycle": {
"hooks": {
"stop": true,
"blur": true,
"focus": true
}
}
}
Some code that shows how I am setting things up. onFocus & onBlur do work fine. The user status is updated as I go to a different tab within Genesys Cloud (onBlur) or when I go back to the app (onFocus)
$scope.clientApp = new window.purecloud.apps.ClientApp({ pcEnvironment: pcEnv })
const onFocus = async evt => { await $scope.applySettings({ status: 'online' })}
const onBlur = async evt => { await $scope.applySettings({ status: 'offline' })}
$scope.clientApp.lifecycle.addBlurListener(onBlur)
$scope.clientApp.lifecycle.addFocusListener(onFocus)
$scope.clientApp.lifecycle.addStopListener(async () => {
await $scope.applySettings({ status: 'offline' })
$scope.clientApp.lifecycle.removeBlurListener(onBlur)
$scope.clientApp.lifecycle.removeFocusListener(onFocus)
$scope.clientApp.lifecycle.stopped()
})
However, and this will be the most likely use-case in real life scenario, a user will just close the browser. This is where I was hoping to be able to use the stop event.
I tried the following to get Stop to trigger:
- Close browser window
- Navigate to another page, leaving GC
Can you please give any insight on why this isn't triggering? Any other ideas to achieve what I need to do?
I also tried handling the 'beforeunload' event on the window, but unfortunately this event handler does not wait for promises to be resolved, and the old way of doing a sync api call is no longer supported for user-experience reasons.
Thanks,
Will