analytics-react-native icon indicating copy to clipboard operation
analytics-react-native copied to clipboard

BackgroundFlushPolicy doesn't flush the Application Backgrounded event

Open sregg opened this issue 1 year ago • 8 comments

    "@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 avatar Aug 07 '23 19:08 sregg

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
  }
}

sregg avatar Aug 07 '23 19:08 sregg

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

oscb avatar Aug 07 '23 22:08 oscb

@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 avatar Aug 07 '23 23:08 sregg

It's also happening on Android.

sregg avatar Aug 08 '23 11:08 sregg

@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?

ekallevig avatar Aug 11 '23 14:08 ekallevig

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 avatar Aug 11 '23 14:08 sregg

Any update on this from the Segment team?

sregg avatar Oct 02 '23 13:10 sregg

Hi @sregg @ekallevig complete apologies here- we have had some turnover in the last year and this simply got lost in the shuffle. I wish I had a better excuse for you.

It seems Oscar had plans to address this but I am not sure he got to it. If this is still an issue would it be possible for you to reach out to [email protected] with a copy of this report? The support engineering team will be able to prioritize this and escalate a fix to us over the course of the next sprint. I will tell their mobile technical product lead to look out for your email so he can be sure to follow up and resolve this as soon as possible.

Apologies again for the delays. Looking forward to resolving this.

alanjcharles avatar Jul 25 '24 15:07 alanjcharles