AppsFlyerSDK / appsflyer-flutter-plugin

Flutter Plugin for AppsFlyer SDK
MIT License
142 stars 111 forks source link

Installs not captured in IOS #288

Closed mufayed closed 4 months ago

mufayed commented 10 months ago

Describe the bug We've encountered a problem with iOS app install tracking using AppsFlyer after integrating the Facebook SDK. Previously, we had no issues, but now iOS installs aren't being recorded. The AppsFlyer integration test also displays variable results, some times it captures the install and sometimes it doesn't capture it, in different builds.

we are calling the following code in the main function: flutter code :

AppsFlyerOptions appsFlyerOptions = AppsFlyerOptions(
          afDevKey: Environment.afDevKey,
          appId: Platform.isIOS ? Environment.appId : '',
          showDebug: false,
          timeToWaitForATTUserAuthorization: 50,
          disableAdvertisingIdentifier: false,
          disableCollectASA: false); // Optional field
      AppsflyerSdk appsflyerSdk = AppsflyerSdk(appsFlyerOptions);
      locator.registerSingleton<AppsflyerSdk>(appsflyerSdk);
      appsflyerSdk.initSdk(
          registerConversionDataCallback: true,
          registerOnAppOpenAttributionCallback: true,
          registerOnDeepLinkingCallback: true);
  }

And here is the swift AppDelegate code:

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    configureFacebookEventsChannel();
    GeneratedPluginRegistrant.register(with: self)
    CleverTap.autoIntegrate()
    CleverTapPlugin.sharedInstance()?.applicationDidLaunch(options: launchOptions)
      allowAdvertiserTracking()
      //facebook required line
      ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
      AppEvents.logEvent(AppEvents.Name("app_opened_ios_custom"))
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

    override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        NSLog("%@: failed to register for remote notifications: %@", self.description, error.localizedDescription)
    }

    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        NSLog("%@: registered for remote notifications: %@", self.description, deviceToken.description)
    }

    override func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {

        NSLog("%@: did receive notification response: %@", self.description, response.notification.request.content.userInfo)
        completionHandler()
    }

    override func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

        NSLog("%@: will present notification: %@", self.description, notification.request.content.userInfo)
        CleverTap.sharedInstance()?.recordNotificationViewedEvent(withData: notification.request.content.userInfo)
        completionHandler([.badge, .sound, .alert])
    }

    override func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        NSLog("%@: did receive remote notification completionhandler: %@", self.description, userInfo)
        completionHandler(UIBackgroundFetchResult.noData)
    }

    func pushNotificationTapped(withCustomExtras customExtras: [AnyHashable : Any]!) {
        NSLog("pushNotificationTapped: customExtras: ", customExtras)
    }

    override func applicationDidBecomeActive(_ application: UIApplication) {
        if #available(iOS 14, *) {
                   requestTrackingAuthorizationAndInitializeFacebook()
               } else {
                   // Handle older iOS versions here, if needed.
               }
        AppEvents.activateApp()
    }

    override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return ApplicationDelegate.shared.application(app, open: url, options: options)
    }

    func allowAdvertiserTracking() {
        Settings.setAdvertiserTrackingEnabled(true)
    }

    @available(iOS 14, *)
        func requestTrackingAuthorizationAndInitializeFacebook() {
            ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
                // Handle the user's response.
                switch status {
                case .authorized:
                    // User has authorized tracking. Initialize Facebook SDK for tracking.
                    Settings.setAdvertiserTrackingEnabled(true)
                case .denied:
                    // User has denied tracking. Adjust tracking behavior if needed.
                    Settings.setAdvertiserTrackingEnabled(false)
                case .notDetermined:
                    // User hasn't made a decision yet. You can prompt the user to make a decision.
                    break
                default:
                    break
                }
            })
        }

    func configureFacebookEventsChannel(){
        let controller = window.rootViewController as! FlutterViewController
        let channel = FlutterMethodChannel(
            name: "facebookEventChannel", binaryMessenger: controller.binaryMessenger
        )

        channel.setMethodCallHandler { call, result in
            if call.method == "signup_user_login" {
               AppEvents.logEvent(AppEvents.Name("signup_user_login"))
            }
        }

    }
}

Please we are seeking your assistance because we are considering changing the AppsFlyer service if we didn't overcome that issue.

Thanks in advance

github-actions[bot] commented 10 months ago

👋 Hi @mufayed and Thank you for reaching out to us. In order for us to provide optimal support, please submit a ticket to our support team at support@appsflyer.com. When submitting the ticket, please specify:

mufayed commented 10 months ago

👋 Hi @mufayed and Thank you for reaching out to us. In order for us to provide optimal support, please submit a ticket to our support team at support@appsflyer.com. When submitting the ticket, please specify:

  • ✅ your AppsFlyer sign-up (account) email
  • ✅ app ID
  • ✅ production steps
  • ✅ logs
  • ✅ code snippets
  • ✅ and any additional relevant information.

email: rudy@souqalmal.com app ID: 6444832869 Production steps: We are pushing the build via xcode to test flight and then to the public Logs: no logs to share code snippets: already in the issue

bgheorghiu commented 4 months ago

@mufayed did you manage to fix it? What was the cause?

mufayed commented 4 months ago

@mufayed did you manage to fix it? What was the cause?

Yes, I think the Flutter SDK has some issues so I integrated the SDK natively in (IOS & Android) and I'm using channels to interact with the SDK like sending events.