Notification analytics on the device

Since plugin version 1.15.0 it is possible to listen to notification events. This feature is especially useful when you want to tie the plugin to your own analytics.

Currently we offer notification events upon showing a notification to the user (sent notification event) and whenever a user taps on a notification (opened notification event).

Whenever such an event happens our plugin will send out an intent to which you can listen with a broadcast receiver. When implementing make sure to include it in the manifest, for example like this:

<receiver android:exported="false" android:name="${applicationId}.MyNotificationEventReceiver">
  <intent-filter>
      <action android:name="${applicationId}.plot.SentNotification" />
      <action android:name="${applicationId}.plot.OpenedNotification" />
  </intent-filter>
</receiver>

See an example implementation below for the notification sent and opened event:

public class MyNotificationEventReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SentNotification notification = intent.getParcelableExtra("notification");
        if ((packageName + ".plot.SentNotification").equals(intent.getAction())) {
          String format = "Message of the sent notification: %s";
          Log.i(TAG, String.format(format, notification.getMessage()));
        } else if ((packageName + ".plot.OpenedNotification").equals(intent.getAction())) {
          String format = "Message of the opened notification: %s";
          Log.i(TAG, String.format(format, notification.getMessage()));
          // Make a call to your Google Analytics
        }
    }
}