Skip to content
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

BackgroundFlushPolicy doesn't flush the Application Backgrounded event #868

Open
sregg opened this issue Aug 7, 2023 · 7 comments
Open
Labels
bug Something isn't working

Comments

@sregg
Copy link

sregg commented Aug 7, 2023

    "@segment/analytics-react-native": "2.15.0",
    "@segment/analytics-react-native-plugin-braze": "^0.5.4",
    "@segment/analytics-react-native-plugin-mixpanel": "0.3.3",
    "@segment/sovran-react-native": "1.0.4",

Steps to reproduce

  1. Add BackgroundFlushPolicy to client flush policies (e.g. segmentClient.addFlushPolicy(new BackgroundFlushPolicy());
  2. Open the app
  3. Trigger an event
  4. Close the app

Expected behavior

  • The event should be visible in Segment's debugger
  • The Application Backgrounded event is also visible in Segment's debugger

Actual behavior

  • The event should be visible in Segment's debugger
  • The Application Backgrounded event is only visible after you re-open the app
@sregg sregg added the bug Something isn't working label Aug 7, 2023
@sregg
Copy link
Author

sregg commented Aug 7, 2023

I tried this custom flush policy but I'm still not seeing the Application Backgrounded until re-opening the app.

class FlushAppBackgroundedPolicy extends FlushPolicyBase {
  start() {
    // no-op
  }

  onEvent(event: SegmentEvent): void {
    if ('event' in event && event.event === 'Application Backgrounded') {
      console.log({ event }); // is logged properly on background
      this.shouldFlush.value = true;
    }
  }

  end(): void {
    // no-op
  }
}

@oscb
Copy link
Contributor

oscb commented Aug 7, 2023

@sregg Thanks for the report! Is this happening in iOS or Android (or both) ?

@sregg
Copy link
Author

sregg commented Aug 7, 2023

@sregg Thanks for the report! Is this happening in iOS or Android (or both) ?

I've only tried on iOS. I'll try Android tomorrow.

@sregg
Copy link
Author

sregg commented Aug 8, 2023

It's also happening on Android.

@ekallevig
Copy link

@sregg I'm wondering about this too. we upgraded from 1.5.2 to 2.10.1 a while back and have noticed a significant increase in delta between event and event_received. i can't seem to find any information about what default flush behavior is for startup and background events. should it be flushing by default in those cases or do you need to set BackgroundFlushPolicy explicitly for that to happen?

@sregg
Copy link
Author

sregg commented Aug 11, 2023

To flush on background you have to add the background policy explicitly I think.
That seems to flush all events except the background event itself.

@sregg
Copy link
Author

sregg commented Oct 2, 2023

Any update on this from the Segment team?

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

3 participants