구글에 Appsflyer의 OneLink로 flutter 연결하는 방법이 자세히 나와있지 않아 제가 하면서 삽질한 내용 써봅니다
각 OS별로 템플릿을 생성해주고 (iOS는 AppID가 있어야 되므로 꼭 앱스토어에 앱을 등록시켜놓자)
템플릿을 등록하고 원링크를 생성했다면 iOS는 내가 만든 원링크도메인을 아래와같이 검색하여 파일을 다운받고 app-site-association제대로 등록되었는지 확인해보면 됩니다!
https://원링크 도메인 알아오기/.well-known/app-site-association.json
flutter에서는 pubspec.yaml에 appsflyer 의존성을 추가해줍니다.
appsflyer_sdk: ^6.최신버전
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;
}
});
이렇게만 설정하면 다 될줄 알고 진행했었는데.. 여기서부터 구글에서는 진짜 정보들이 안나와서 엄청 삽질을 했었습니다 ㅠㅠㅠ 여튼 각 네이티브 별로 설정해줘야 될게 좀 있습니다 ! 우선 안드로이드 부터 살펴보겠습니다 ㅎㅎ
<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>
위와 같이 탬플릿 이름, 키 , 스키마와 호스트 등 필요 정보를 기입해주셔야 됩니다 ㅎㅎ
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")
}