segmentio / analytics_flutter

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

AppsFlyer Destination not initializing properly #98

Open ClaireDavis opened 3 weeks ago

ClaireDavis commented 3 weeks ago

Hello - I'm attempting to migrate my app to use the latest analytics_flutter package, but when I try to add the appsflyer plugin, it doesn't initialize properly.

This is how I'm setting up my analytics client:

    analyticsClient = createClient(
      Configuration(
        _segmentWriteKey ?? '',
      ),
    )
      ..addPlugin(AppsFlyerDestination())
      ..addPlugin(PluginAdvertisingId());

Then when update is called in AppsFlyerDestination, the settings map is null so it returns early on line 24 of plugin_appsflyer.dart. Later when identify is called, there is a userId, but then line 61 throws an error because it's force unwrapping appsFlyer which was never set in update because of the early return.

How can I get this to work properly?

ClaireDavis commented 3 weeks ago

Here's an example project that shows the issue

https://github.com/ClaireDavis/segment_analytics_test

edsonjab commented 3 weeks ago

Hi @ClaireDavis thank you for your report, we start looking into this.

edsonjab commented 1 week ago

Hi @ClaireDavis sorry to answer late, I can't replicate the issue, could you help me to show us the logs with the error please?

ClaireDavis commented 1 week ago

@edsonjab

In order to repro the error, I had to add a write key to the configuration. I then get this error on running the app and letting it load:

Launching lib/main.dart on iPhone 15 in debug mode...
Xcode build done.                                           18.9s
Connecting to VM Service at ws://127.0.0.1:52481/PzlgjxLpe4Q=/ws
Connected to the VM Service.
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0      AppsFlyerDestination.track (package:segment_analytics_plugin_appsflyer/plugin_appsflyer.dart:110:22)
plugin_appsflyer.dart:110
#1      EventPlugin.execute (package:segment_analytics/plugin.dart:54:16)
plugin.dart:54
#2      DestinationPlugin.process (package:segment_analytics/plugin.dart:163:17)
plugin.dart:163
<asynchronous suspension>
this is the output of my flutter doctor: ``` [✓] Flutter (Channel stable, 3.24.0, on macOS 14.6.1 23G93 darwin-arm64, locale en-US) • Flutter version 3.24.0 on channel stable at /Users/clairedavis/fvm/versions/3.24.0 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 80c2e84975 (5 weeks ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/clairedavis/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_SDK_ROOT = /Users/clairedavis/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) [✓] VS Code (version 1.92.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (5 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 14 (API 34) (emulator) • iPhone 15 (mobile) • 9ED72432-71DD-4404-8BCA-8D601A3A5F12 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.6.1 23G93 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.6.1 23G93 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.114 ! Error: Browsing on the local area network for Claire’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources • All expected network resources are available. ```

I've attached a zip showing the issue. You'll notice that settings is null at first which triggers an early return but then tracking events force unwrap appsFlyer even though it was never initialized.

segment_error_screen_recording.mov.zip

edsonjab commented 3 days ago

Hi @ClaireDavis sorry to answer late, this is an example to use the AppsFlyerDestination plugin: image