segmentio / analytics_flutter

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

`Application Backgrounded` events send `properties` as null, but `properties` should always be an object #60

Closed niallzato closed 3 months ago

niallzato commented 4 months ago

The automatically collected Application Backgrounded event should send an empty properties as an empty object, and not as null.

 "event": "Application Backgrounded",
  "integrations": {},
  "messageId": "d7ee8923-280f-4224-86b7-117ae34771c3",
  "originalTimestamp": "2024-02-22T03:34:17.882927",
  "properties": null,
  "receivedAt": "2024-02-22T08:34:24.593Z",
  "sentAt": "2024-02-22T03:34:23.476Z",
  "timestamp": "2024-02-22T08:34:18.999Z",
  "type": "track",

The Segment spec specifies this should be an object: https://segment.com/docs/connections/spec/track/

As an interim workaround, a plugin can be used to change the format:

class PropertyFixPlugin extends Plugin {
  PropertyFixPlugin() : super(PluginType.enrichment);

  @override
  void configure(Analytics analytics) {
    super.configure(analytics);

    if (kIsWeb) {
      return;
    }
  }

  @override
  Future<RawEvent?> execute(RawEvent event) async {
    var local = event.type.toString();
    if (local == 'track') {
      var track = event as TrackEvent;
      final properties = track.properties;

      if (properties == null) {
        track.properties = {};
      }
    }

    return event;
  }

}
edsonjab commented 4 months ago

Hi @niallzato thank you for your report. We start looking into this.