countly-sdk-react-native-bridge icon indicating copy to clipboard operation
countly-sdk-react-native-bridge copied to clipboard

Foreground Push Notifications (Android)

Open peterkuiper opened this issue 1 year ago • 12 comments
trafficstars

In an Expo project I am working on, foreground Push Notifications are "hijacked" by countly-sdk-react-native-bridge on Android. After removing countly-sdk-react-native-bridge, foreground Push Notifications on Android work as expected.

We only want to use certain parts of Countly, but not Push Notifications. I did not find any option to disable Push Notifications from within the countly-sdk-react-native-bridge package.? I tried to disable it by patching the module itself but it seems the initialization is done in the Countly Android SDK.

It would be nice to be able to opt-in to the Countly Push Notifications service.

peterkuiper avatar Jun 24 '24 11:06 peterkuiper

Hello @peterkuiper,

Are you experiencing this issue only on Android, or does it affect both platforms?

Can you elaborate more on ‘foreground Push Notifications are “hijacked” by countly-sdk-react-native-bridge on Android’?

Additionally, could you please share your SDK initialization code with us? It would also be helpful if you could check your codebase for any instances of the following methods:

  • Countly.registerForNotification
  • Countly.askForNotificationPermission

peterBrxwn avatar Jun 25 '24 12:06 peterBrxwn

Hi @peterBrxwn We are only experiencing this on Android, iOS works fine.

As said, we are using Expo Push Notifications. Without the countly-sdk-react-native-bridge module installed, push notifications are received by the Expo push notification handlers when the app is in the foreground (i.e. the app is open) and background (or killed).

With the countly-sdk-react-native-bridge module installed, push notifications work, but only when the app is in the background (or killed). So when the app is in the foreground, it seems the countly-sdk-react-native-bridge module handles the incoming push notification, instead of the Expo push notification module. Hence the "hijacking".

This is the init function:

const enableCountlyAsync = async () => {
  if (__DEV__) {
    return false;
  }

  // Setup Countly
  try {
    const initialized = await Countly.isInitialized();

    if (!initialized) {
      // Disable Countly internal debugging logs
      Countly.setLoggingEnabled(false);

      // Require consent for all features
      Countly.setRequiresConsent(true);

      // Ensure that consent is required for features to work
      Countly.giveConsentInit(['events', 'views', 'sessions', 'scrolls', 'clicks']);

      // Initialize the countly SDK.
      await Countly.init(localConfig.countly.url, localConfig.countly.appKey);

      // Disable location tracking
      Countly.disableLocation();

      // Start session tracking
      Countly.start();

      return true;
    }
  } catch (error) {
    if (__DEV__) {
      console.log('[enableCountlyAsync]', 'catch', error); // eslint-disable-line no-console
    }
  }

  return false;
};

These methods aren't called anywhere in our code:

  • Countly.registerForNotification
  • Countly.askForNotificationPermission

We only use the Countly.recordView method.

peterkuiper avatar Jun 25 '24 19:06 peterkuiper

Hi @peterkuiper,

Thank you for your prompt response.

Quick question: What version of the Countly SDK are you using?

peterBrxwn avatar Jun 25 '24 19:06 peterBrxwn

@peterBrxwn I tried until version 23.12.0, same issue. The current version in production use is 21.11.2.

peterkuiper avatar Jun 28 '24 05:06 peterkuiper

@peterBrxwn Any updates on this yet ?

thanks!

jdodds-pxhealthcare avatar Jul 02 '24 07:07 jdodds-pxhealthcare

@jdodds-pxhealthcare

We are currently investigating the issue. We will provide an update as soon as possible.

peterBrxwn avatar Jul 03 '24 00:07 peterBrxwn

Hi @peterBrxwn ! Is there any updates with this issue?

pavelPX avatar Jul 15 '24 12:07 pavelPX

Hello @pavelPX, We are working on a no push variant. Should be available within this month. I will post it here when it is ready.

peterBrxwn avatar Jul 16 '24 12:07 peterBrxwn

Great news! Thank you @peterBrxwn

pavelPX avatar Jul 16 '24 20:07 pavelPX

Hello @pavelPX, @jdodds-pxhealthcare and @peterkuiper,

We've released a "No Push Notifications" variant of the SDK without FCM libraries and with Push related methods ignored.

You can find it on NPM here: https://www.npmjs.com/package/countly-sdk-react-native-bridge-np or on Github from here: https://github.com/Countly/countly-sdk-react-native-bridge/releases/tag/24.4.0-np

peterBrxwn avatar Jul 24 '24 12:07 peterBrxwn

Good news @peterBrxwn! Will test it soon. Thank you!

pavelPX avatar Jul 25 '24 03:07 pavelPX

Hello @pavelPX, @jdodds-pxhealthcare and @peterkuiper,

We've released a "No Push Notifications" variant of the SDK without FCM libraries and with Push related methods ignored.

You can find it on NPM here: https://www.npmjs.com/package/countly-sdk-react-native-bridge-np or on Github from here: https://github.com/Countly/countly-sdk-react-native-bridge/releases/tag/24.4.0-np

Thanks to you and your team for the fast response! Cheers!

jdodds-pxhealthcare avatar Jul 25 '24 08:07 jdodds-pxhealthcare