Skip to content

Lifecycle events not sent #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lironzemingo opened this issue Nov 26, 2023 · 4 comments · Fixed by #45 or #52
Closed

Lifecycle events not sent #42

lironzemingo opened this issue Nov 26, 2023 · 4 comments · Fixed by #45 or #52

Comments

@lironzemingo
Copy link

Hi,
I'm creating the client in the following way:
_analyticsClient = createClient( Configuration(FlavorHelper.getSegmentWriteKey(), trackApplicationLifecycleEvents: true, debug: kDebugMode));
but lifecycle events are not sent properly. only "Application Opened" is sent on app launch, but not "Application Installed" or "Application Backgrounded" .
why is this happening? is the configuration right?

Tested on an Android Samsung S22, Android 13 OS.

@edsonjab
Copy link
Contributor

Hi @lironzemingo thank you for your report, we start looking into this.

@QoLTech
Copy link

QoLTech commented Nov 27, 2023

I also don't get Application Installed events.

@lironzemingo
Copy link
Author

@edsonjab I think I figured it out. in createClient:

Analytics createClient(Configuration configuration) {
  if (configuration.debug) {
    Analytics.debug = true;
  }
  if (configuration.flushPolicies == null) {
    configuration = setFlushPolicies(configuration, defaultFlushPolicies);
  }

  final analytics = Analytics(configuration, storeFactory());

  if (configuration.debug) {
    analytics.addPlugin(EventLogger());
  }

  analytics.init();
  ScreenObserver().screenStream.listen((name) {
    analytics.screen(name);
  });

  return analytics;
}

you're initializing and persisting the ContextState in the creation of the Analytics() object.
then, you're calling analytics.init() -> _checkInstalledVersion() ->
if (previousContext == null) { track("Application Installed", properties: { "version": context.app.version, "build": context.app.build, }); }
but previousContext will never be null, because it was persisted before, so "Application Installed" will never be tracked.

@QuirijnGB
Copy link

When is this being merged into main? Currently sitting in a branch

oscb added a commit that referenced this issue Jan 12, 2024
- Fixes Lifecycle events not sent #42 lifecycle events Foreground/Background not being detected and sent properly.
- Adds FgBg as a dependency again since iOS/Android have incorrect behaviours when system UI is shown on top of the app. WidgetObserver lifecycle detection is still the default for all other platforms.
- Refactors the lifecycle to simplify and remove unused classes.
- Refines the solution for App Installed events with shared_preferences to prevent pollution on the context JSON object
- Ignores Installed/Updated events on web
- chore: I removed Firebase from the example since it's a little bit of hassle to run it as you have to register for firebase. It also brings a lot of dependencies. Let's keep it simple for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants