Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appsflyer help #99

Closed
GeorgePagMezzi opened this issue Aug 28, 2024 · 7 comments
Closed

Appsflyer help #99

GeorgePagMezzi opened this issue Aug 28, 2024 · 7 comments

Comments

@GeorgePagMezzi
Copy link

GeorgePagMezzi commented Aug 28, 2024

Hello, I just switched over from deprecated Segment package to this one and would like to also include Appsflyer support in order to track attribution data through Segment in my ios app. In my Segment dashboard I have added the 'Appsflyer' destination and included the Apple APP ID, Appsflyer Dev Key andhave enabled 'Track Attribution Data' option. Code on the FE looks like this:

final clientAnalytics = createClient(
  Configuration(
    "KEY",
    /// This is set to false to avoid swarming the console messages. If Segment debug is needed set it to true.
    debug: false,
    trackApplicationLifecycleEvents: true,
    trackDeeplinks: true,
  ),
);
clientAnalytics.addPlugin(AppsFlyerDestination());

Sadly the attribution does not work on Segment side with this setup (even though deprecated package was somewhat consistent with attribution). Is there anything more I should do? E.G. create an appsflyerDestination object and manually input the settings?

final AppsFlyerDestination appsFlyerDestination = AppsFlyerDestination();
appsFlyerDestination.appsFlyerSettings = AppsFlyerSettings(
        appleAppID, appsFlyerDevKey, httpFallback, rokuAppID, trackAttributionData, type, versionSettings);
clientAnalytics.addPlugin(appsFlyerDestination);

When should I run the identify method of AppsFlyerDestination class? I also notice that in your docs it says: 'When you send this flag the plugin_appsflyer SDK ignores attribution. What does it mean when you say 'send' (do you mean 'set')? is the plugin_appsflyer sdk the same as segment_analytics_plugin_appsflyer?
image

Also if I Restart the app, I get below error. I have declared the clientAnalytics variable globally.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0 AppsFlyerDestination.identify (package:segment_analytics_plugin_appsflyer/plugin_appsflyer.dart:61:16)
plugin_appsflyer.dart:61
#1 EventPlugin.execute (package:segment_analytics/plugin.dart:52:16)
plugin.dart:52
#2 DestinationPlugin.process (package:segment_analytics/plugin.dart:163:17)
plugin.dart:163

Thank you in advance and remain at your disposal to provide further info.

@edsonjab
Copy link
Contributor

edsonjab commented Sep 3, 2024

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

@edsonjab
Copy link
Contributor

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

@GeorgePagMezzi
Copy link
Author

GeorgePagMezzi commented Sep 13, 2024

Thank you @edsonjab , so appsflyer plugin does not sync from Segment cloud some time after adding it as a plugin to the Analytics client, based on the settings we have set up on Segment destination dashboard? I looked into it a bit more these days and it appears that after doing

clientAnalytics.addPlugin(appsFlyerDestination);
    Function? removeListener;
    removeListener = clientAnalytics.state.integrations.addListener((integrationMap) {
      if (integrationMap['AppsFlyer'] != null) {
        appsFlyerDestination.identify(
          IdentifyEvent(
            userId: FirebaseAuth.instance.currentUser?.uid,
          ),
        );
        if (removeListener != null) {
          removeListener();
        }
      }
    });

This integrationMap['AppsFlyer'] object is filled by some values which appear in sync with what is on Segment dashboard, but the above code can still sometimes fail when identify is called due to the exception

Unhandled Exception: Null check operator used on a null value
#0 AppsFlyerDestination.identify (package:segment_analytics_plugin_appsflyer/plugin_appsflyer.dart:61:16)

if I

await Future.delayed(seconds: 5) //e.g. and run identify again
   appsFlyerDestination.identify(
          IdentifyEvent(
            userId: FirebaseAuth.instance.currentUser?.uid,
          ),
        );

Then the error goes away, which makes me thing Segment makes some api calls when we add appsflyer as a pluging, but we have no way to await the initialization of appsflyer. I will try your response, but it would be great if we had a way to await the initialization of the destination.

@GeorgePagMezzi
Copy link
Author

Also it would be great if that Map<String,dynamic> settings object in your screenshot was an object, to avoid misstyping the keys.

@GeorgePagMezzi
Copy link
Author

@edsonjab When implementing solution from screenshot I get below error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0 AppsFlyerDestination.update (package:segment_analytics_plugin_appsflyer/plugin_appsflyer.dart:27:35)
plugin_appsflyer.dart:27

and the app hangs upon startup when update is called.

@edsonjab
Copy link
Contributor

This happened once the state inside the configuration is not initialized properly, for that reason is important add plugin AppsFlyerDestination after Analytics was created with all configurations:

image

In that line is failing your code.

@GeorgePagMezzi
Copy link
Author

I will be closing this issue, as we switched package since package still seems a bit behind the deprecated one. Thank you for trying to solve this! A better documentation or code examples would be great for these kind of issues. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants