Lifecycle api - stop event not triggering

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:

  1. Close browser window
  2. 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

Hi William,

The dev forum is for customers and partners only. Employees should use internal avenues for support. Thanks!

The stop event is triggered whenever an app is torn down. This can be if the app needs to be evicted from a pool, if the app config changes and the user reloads the app (standalone/widget only), when an interaction is removed from an agent and the interaction widget is torn down, or if the entire Genesys Cloud application is closed.

As you point out, the last mechanism is unreliable as the beforeunload event cannot be haulted or cancelled. So, while we attempt to trigger the stop event, it will be unreliably delivered to apps.

The stop event would be best used for resource cleanup and most effective in the other tear down cases. In those cases, your app will remain in the dom for a period of time to allow your js to clean-up.

Usage tracking would probably be best done on load and/or maybe via a heartbeat if you want to track temporal usage vs user-level usage.

Hope this helps,
Justin

1 Like

Thanks for the thorough answer. I went with a heartbeat mechanism.

1 Like

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