Skip to content

Lifecycle method application_opened not firing consistently #1072

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
mattlennon3 opened this issue May 9, 2025 · 2 comments
Closed

Lifecycle method application_opened not firing consistently #1072

mattlennon3 opened this issue May 9, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@mattlennon3
Copy link

Our analytics team have flagged that we aren't always receiving an application_opened event for app sessions. Even though other events are received on the same day. This can be as high as 10% of users who's session does not trigger the event.

We believe this could be to do with the app being backgrounded for an extended period of time.

I am raising this issue to ask for advice on how to replicate, and of course if you have any ideas what the problem might be.

Is it advisable to try to fire an event ourselves on app opening/closing? We feel like it's possible, but would be a last resort.

  • analytics-react-native version:
  • Integrations versions (if used):
    "@segment/analytics-react-native": "2.18.0",
    "@segment/analytics-react-native-plugin-advertising-id": "1.3.1",
    "@segment/analytics-react-native-plugin-appsflyer": "0.7.0",
    "@segment/analytics-react-native-plugin-firebase": "0.4.1",
    "@segment/analytics-react-native-plugin-idfa": "0.7.2",
    "@segment/sovran-react-native": "1.1.0",
  • React Native version:
    "react-native": "0.74.6"
  • iOS or Android or both?
    At least iOS, I think Android also.

Steps to reproduce

Unfortunately nothing concrete in terms of replication steps.

Expected behavior

This lifecycle method is fired every time the app is opened.

Actual behavior

It seems like it is not always fired, as other events are received, but not this one.

@mattlennon3 mattlennon3 added the bug Something isn't working label May 9, 2025
@mattlennon3
Copy link
Author

Found the relevant code.

I'm wondering if this check:

      if (
        ['inactive', 'background'].includes(this.appState) && // the previous `appState` could have been `unknown` or something else.
        nextAppState === 'active'
      ) {
        const context = this.store.context.get();
        const event = createTrackEvent({
          event: 'Application Opened',
          properties: {
            from_background: true,
            version: context?.app?.version,
            build: context?.app?.build,
          },
        });

As indicated by the comment, I feel like there maybe some risk if the state is incorrect.

In fact, I found an MR in this very repo: https://github.com/segmentio/analytics-react-native/pull/887/files which checks for unknown in the background flush policy.

Perhaps these changes can be checked and aligned.

@sunitaprajapati89
Copy link
Contributor

@mattlennon3 : I would like you to pay attention to the comment added above the [relevant code]. It says that "The initial event from 'unknown' to 'active' is handled on launch in checkInstalledVersion" and checkInstalledVersion is called inside init. I hope that makes sense to you.

I request you to kindly provide more details that would help us to reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants