segmentio / analytics_flutter

The hassle-free way to add Segment analytics to your Flutter app.
MIT License
26 stars 33 forks source link

Is there a way to track a `Push Notification Received` event? #57

Closed omarhussein-ava closed 4 months ago

omarhussein-ava commented 4 months ago

As the question on the title says, we want to track this event using the Segments SDK, how to activate it?

We're using Flutter 3.19.6 and the following dependencies:

  analytics:
    git:
      url: https://github.com/segmentio/analytics_flutter
      ref: main
      path: packages/core
  analytics_plugin_firebase:
    git:
      url: https://github.com/segmentio/analytics_flutter
      ref: main
      path: packages/plugins/plugin_firebase
edsonjab commented 4 months ago

Hi @omarhussein-ava You can build your custom plugin adding the firebase_messaging to identify when you receive a message, something like:

// Handle incoming messages when the app is in the foreground
    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
       analytics.track("Message Received", properties: {})
    });

You can use the track method in the moment that you receive the notification.

omarhussein-ava commented 4 months ago

Thank you, closing this.