AppsFlyer OneLink Flutter에 연결하기

yong·2025년 4월 21일

flutter

목록 보기
1/4

구글에 Appsflyer의 OneLink로 flutter 연결하는 방법이 자세히 나와있지 않아 제가 하면서 삽질한 내용 써봅니다

1. 템플릿 생성하기

각 OS별로 템플릿을 생성해주고 (iOS는 AppID가 있어야 되므로 꼭 앱스토어에 앱을 등록시켜놓자)
템플릿을 등록하고 원링크를 생성했다면 iOS는 내가 만든 원링크도메인을 아래와같이 검색하여 파일을 다운받고 app-site-association제대로 등록되었는지 확인해보면 됩니다!

https://원링크 도메인 알아오기/.well-known/app-site-association.json

2. flutter

flutter에서는 pubspec.yaml에 appsflyer 의존성을 추가해줍니다.

appsflyer_sdk: ^6.최신버전

1. dart

Dart파일에서 Appsflyer를 초기화 해주면 됩니다.

late final AppsflyerSdk _appsFlyerSdk;

  AppsFlyerOptions options = AppsFlyerOptions(
  	  // 앱스플라이어 생성하면 주는 키를 입력하면 됩니다.
      afDevKey: "DEV_KEY",

      // appId: "", // 앞서 말했듯이 iOS도 사용하려면 appstore에 등록하고 AppID가 필요합니다.
      showDebug: kDebugMode,
      disableCollectASA: false,
      disableAdvertisingIdentifier: false,
      manualStart: true,
    );
    _appsFlyerSdk = AppsflyerSdk(options);
    
Future<void> initAppsFlyer() async {
await _appsFlyerSdk
    .initSdk(
  registerConversionDataCallback: true,
  registerOnDeepLinkingCallback: true,
).then((value) {
  _appsFlyerSdk.startSDK(
    onSuccess: () {
      debugPrint("AppsFlyer baek successfully. $value");
    },
    onError: (int errorCode, String errorMessage) {
      debugPrint(
        "AppsFlyer baek initializing SDK $errorCode - $errorMessage.",
      );
    },
  );
});

_appsFlyerSdk.onDeepLinking((DeepLinkResult result) {
  debugPrint("test : onDeepLinking $result");
  switch (result.status) {
    case Status.FOUND:
    //여기서 값이 잘 들어왔다면 원링크에 설정해두었던 파라미터들을 esult.deepLink?.clickEvent['']로 추출해낼수있습니다.
      debugPrint(
        "test : deepLink 값은? ?  ${result.deepLink?.clickEvent['deep_link_value']}",
      );

      notifyListeners();
      break;
    case Status.NOT_FOUND:
      print("test : ${result}");
      notifyListeners();
      break;
    case Status.ERROR:
      print("test : ${result}");
      notifyListeners();
      break;
    case Status.PARSE_ERROR:
      print("test : ${result}");
      notifyListeners();
      break;
  }
});

이렇게만 설정하면 다 될줄 알고 진행했었는데.. 여기서부터 구글에서는 진짜 정보들이 안나와서 엄청 삽질을 했었습니다 ㅠㅠㅠ 여튼 각 네이티브 별로 설정해줘야 될게 좀 있습니다 ! 우선 안드로이드 부터 살펴보겠습니다 ㅎㅎ

Android

  1. AndroidManifest에 스키마 호스트 정의
  • 원링크를 타고 앱이 실행될 떄 AndroidManifest를 통해 읽어와야 될 데이터들이 꽤 있습니다.
<meta-data
    android:name="com.appsflyer.AF_DEV_KEY"
    android:value="키 넣기" />
<meta-data
           android:name="com.appsflyer.ONELINK_ID"
           android:value="템플릿 이름" />
		
		<receiver
		    android:name="com.appsflyer.MultipleInstallBroadcastReceiver"
		    android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER"/>
    </intent-filter>
</receiver>

<activity>
 <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:scheme="${scheme}"
                    android:host="${host}" />
</intent-filter>
</activity>

위와 같이 탬플릿 이름, 키 , 스키마와 호스트 등 필요 정보를 기입해주셔야 됩니다 ㅎㅎ

  1. buila.gradle.kts defaultconfig 정의
  defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.crepass.score.kr"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 24
        targetSdk = 35
        versionCode = 1
        versionName = "1.0.0"
        manifestPlaceholders.put("scheme", "com.example.app")
        manifestPlaceholders.put("host", "example")
 }
    
dependencies{
implementation ("com.appsflyer:af-android-sdk:6.15.2")

}

iOS

  1. 앱스토어에 앱 등록 (App ID 있어야 됨)
  2. https://원링크 도메인 알아오기/.well-known/app-site-association.json 조회해서 사이트 있나 없나 확인 해보기
  3. Signing & Capabilities에서 Associated Domains 등록하기
    applinks:domain.onelink.me
  4. 스위프트 내부에 바꿀건 없는데 따로 설정해줘야될게 있음
    1. 원링크 테스트를 할려는데 Flutter앱은 debug모드에서 앱을 종료시키고 다시 키면 바로 꺼짐 → release모드에서 실행해야 원하는 딥링크 테스트 가능함.
    2. info.plst에서 무조건 FlutterDeepLinkingEnabled를 yes로 해줘야 됨 !! 이게 젤 중요 → 이거 안하면 딥링크로 앱 열면 안열림
profile
배우고 경험한거 꾸준히 복습

0개의 댓글