aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.3k stars 239 forks source link

Expose `StartSession` for `Pinpoint` plugin #1056

Open potter420 opened 2 years ago

potter420 commented 2 years ago

We would like to manually stop then start a session in-app after certain actions. For example: When user logout, we want to stop and start a new session for tracking

How can we do this with the existing API or can we expose the StartSession method. I saw that we have a start session methods.

Thank you.

fjnoyp commented 1 year ago

Hi @potter420 thanks for your patience here.

This is not officially supported in our API, but it will be possible in the next update to the Developer Preview Release for Analytics.

When creating an instance of Analytics, you can pass your own implementation of the AppLifecycleProvider class.

AmplifyAnalyticsPinpoint(
      appLifecycleProvider: myAppLifecycleProvider,
)

When this class calls the provided onForeground and onBackground methods a new session will be started or stopped (please note a new session can only be started if it was stopped before).

This isn't officially supported because the appLifecycleProvider is marked as 'visibleForTesting' as we are still evaluating how we should expose this functionality publicly. But for now you can use it for your use case and we can update you on future changes.

fjnoyp commented 1 year ago

There might be a better way to handle this for you guys. I will investigate a bit internally for a solution.