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

Event is not sent when the android app is in the background - firebase messaging #914

Open
Rafazor opened this issue Jan 23, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@Rafazor
Copy link

Rafazor commented Jan 23, 2024

I'm trying to track when a notification is received. I'm using @react-native-firebase/messaging.

Current implementation:

 messaging().setBackgroundMessageHandler(async (remoteMessage) => {
    await track("notification.received", {
          notification_id: remoteMessage.messageId,
          title: remoteMessage.notification?.title,
        });
});

setBackgroundMessageHandler is called every time a notification is received, but the track event is sent only when the app is in the foreground and not in the background. Other API calls are working as expected when they are called from setBackgroundMessageHandler.

  • @segment/analytics-react-native": "^2.13.5"
  • "react-native": "0.70.1",
  • "@react-native-firebase/messaging": "^17.4.3",

Steps to reproduce
Put the app in the background and generate a notification.

Expected behavior
The event (notification.received) is sent to Segment.

Actual behavior
The event is not sent when a notification is received, it's only sent later on when the app is back in the foreground.

@Rafazor Rafazor added the bug Something isn't working label Jan 23, 2024
@oscb
Copy link
Contributor

oscb commented Mar 18, 2024

Last I knew RN completely stopped execution of JS as soon as the app goes into the background in Android (not for iOS). Has this changed?

Will have to retest to verify.

@mattlennon3
Copy link

mattlennon3 commented Apr 23, 2024

We're seeing the same behaviour. Very occasionally we get some result, but it's less than 10% of the time.

JS will run in the background for firebase messaging as it uses registerHeadlessTask. See the headless JS docs here.

Firebase messaging uses this here and the entrypoint in the same file here

We're using these packages:

"@react-native-firebase/app": "15.7.1",
"@react-native-firebase/analytics": "15.7.1",
"@segment/analytics-react-native": "2.18.0",
"@segment/analytics-react-native-plugin-firebase": "0.4.1",

@mattlennon3
Copy link

mattlennon3 commented Apr 23, 2024

@Rafazor do you still have this problem? I'm curious about this line:

The event is not sent when a notification is received, it's only sent later on when the app is back in the foreground.

This would be acceptable to us, but we don't see this. Are you doing some storage/queueing of the event to be sent later?

EDIT:
While doing some testing today, I saw some events from last Friday, meaning something is being stored by segment..
Screenshot 2024-04-23 at 11 49 47

@Rafazor
Copy link
Author

Rafazor commented Apr 23, 2024

@mattlennon3 @oscb Thank you for your time and answers. In the meantime, I switched companies and don't have access to the codebase to confirm that the issue is still present. :)

Our goal was to improve notification convergence, and we needed a way to track the number of notifications received and after that from that number of notification.received events we wanted to track how many notifications were used to open the app so the current behavior on Android ("The event is not sent when a notification is received, it's only sent later on when the app is back in the foreground.") was not super helpful because a lot of times you receive a notification but you don't actually check it.

@mattlennon3
Copy link

mattlennon3 commented Apr 23, 2024

Thanks for the response @Rafazor. That was our thinking too, the ratio of sent:received:pressed.
Our pressed tracking works, but only because it opens the app to handle the notification press.
I think sent:pressed is not as useful to compare.

I reviewed some of the Segment code. There is some storage of events and a Timeline class, but I couldn't see anything of concern. I think it'll need to be set up locally and checking etc. I can't give the time unfortunately.

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