You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter延迟深度链接问题:安装后获取推荐码与事件ID

Solution for Flutter Referral System (Uninstalled App Scenario)

Android: Fixing Install Referrer Retrieval

If android_play_install_referrer didn’t work, verify your implementation with these steps:

  • Add the package to pubspec.yaml:

    dependencies:
      android_play_install_referrer: ^latest_version
    
  • Initialize and listen for the referrer in your splash screen or initial screen:

    import 'package:android_play_install_referrer/android_play_install_referrer.dart';
    
    @override
    void initState() {
      super.initState();
      _fetchInstallReferrer();
    }
    
    Future<void> _fetchInstallReferrer() async {
      try {
        final referrerDetails = await AndroidPlayInstallReferrer.installReferrer;
        if (referrerDetails != null) {
          // Parse the referrer string to extract your parameters
          final params = Uri.splitQueryString(referrerDetails.installReferrer);
          final referrerCode = params['REFERRERCODE'];
          final eventId = params['eventId'];
          
          // Use these values to continue the referral flow
          if (referrerCode != null && eventId != null) {
            // Save or process the referral data
          }
        }
      } catch (e) {
        // Handle errors (e.g., API unavailable on older Android versions)
      }
    }
    
  • Critical note: The referrer is only retrieved once on the first app launch after installation. Test this by uninstalling the app, clicking your Play Store link, then reinstalling and launching.

iOS doesn’t support passing referrer parameters directly through App Store links. Use Firebase Dynamic Links for a reliable cross-platform solution that works for both Android and iOS:

  • Enable Dynamic Links in your Firebase project and configure your app’s bundle ID.
  • Add the package to pubspec.yaml:
    dependencies:
      firebase_dynamic_links: ^latest_version
    

Create a link that includes your referral parameters. You can do this via the Firebase Console or programmatically:

final dynamicLinkParams = DynamicLinkParameters(
  uriPrefix: 'https://yourapp.page.link', // Replace with your Firebase prefix
  link: Uri.parse('https://yourapp.com/refer?referrerCode=$REFERRERCODE&eventId=$EVENTID'),
  androidParameters: AndroidParameters(
    packageName: 'com.yourapp.android',
    minimumVersion: 1,
  ),
  iosParameters: IosParameters(
    bundleId: 'com.yourapp.ios',
    minimumVersion: '1.0',
  ),
);
final shortLink = await dynamicLinkParams.buildShortLink();
final referralUrl = shortLink.shortUrl.toString();

Step 3: Retrieve Parameters in the App

Listen for dynamic links when the app launches:

@override
void initState() {
  super.initState();
  _initDynamicLinks();
}

Future<void> _initDynamicLinks() async {
  // Check for initial link (app opened from link while closed)
  final initialLinkData = await FirebaseDynamicLinks.instance.getInitialLink();
  final deepLink = initialLinkData?.link;

  if (deepLink != null) {
    final referrerCode = deepLink.queryParameters['referrerCode'];
    final eventId = deepLink.queryParameters['eventId'];
    // Process referral data
  }

  // Listen for links while the app is open
  FirebaseDynamicLinks.instance.onLink.listen((linkData) {
    final deepLink = linkData.link;
    if (deepLink != null) {
      // Handle ongoing referral links
    }
  }).onError((error) {
    // Handle link errors
  });
}

Alternative: Custom Web Redirect (No Firebase)

If you prefer not to use Firebase, build a simple web endpoint that:

  1. Stores referral parameters (along with a device identifier like advertising ID or IP) when the user clicks the link.
  2. Redirects the user to the appropriate app store.
  3. When the app first launches, sends a request to your endpoint to retrieve the stored parameters using the same device identifier.

This requires backend development but gives you full control over the referral flow.

内容的提问来源于stack exchange,提问作者Siddhesh Kumbhar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:55:11