연동하기
이 문서는 Dfinery SDK를 Flutter에 통합하는 방법을 다룹니다. Dfinery SDK를 설치하면 이벤트 분석 기능과 유저 프로필 기능 그리고 액션 기능이 제공됩니다.
시작하기 전에
서비스 설정
DFINERY 콘솔의 서비스 관리/서비스 정보 페이지에서 데이터 소스 항목에 사용하시려는 플랫폼을 체크하셔야 합니다.
지원 정보
Android
최소 지원 SDK : Android 4.4+ / API 19+
Compile SDK : 34
iOS
iOS 12.0
Xcode 16.0
의존성
Android
SDK 설치
pubspec.yaml에 Dfinery 패키지를 추가합니다.
Flutter 프로젝트의 pubspec.yaml
파일에 다음과 같이 Dfinery Flutter SDK 패키지를 추가하세요.
dependencies:
dfinery_plugin: ^1.0.0
패키지를 추가한 후 터미널에서 다음 명령어를 실행하세요:
flutter pub get
SDK 설정하기
1. 권한 추가
android/app/src/main/AndroidManifest.xml
에 필요한 권한을 등록해주세요.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
2. 설정 완료.
다음은 작성이 완료된 AndroidManifest.xml
예시입니다.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SDK 초기화
초기화 하기
앱에서 Dfinery SDK를 초기화하려면 다음 단계를 완료하세요.
1. main.dart에 Dfinery를 import합니다.
import 'package:dfinery_plugin/dfinery_plugin.dart';
2. 앱 초기화 시점에 다음 코드를 작성합니다.
import 'package:dfinery_plugin/dfinery_plugin.dart';
Dfinery.init(serviceId: "YOUR_SERVICE_ID");
3. 초기화가 완료되었습니다.
구글 광고 ID 설정하기(선택사항)
Google 광고 ID를 수집하기 위해선 setGoogleAdvertisingId()
메소드를 통해 수동으로 설정해야합니다.
1. android/app/src/main/AndroidManifest.xml에 필요한 권한을 추가합니다.
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
2. setGoogleAdvertisingId()
메소드를 통해 광고 ID를 설정합니다.
setGoogleAdvertisingId()
메소드를 통해 광고 ID를 설정합니다.void refreshGoogleAdvertisingId() {
Dfinery.getGoogleAdvertisingId().then((value) {
if (value != null) {
Dfinery.setGoogleAdvertisingId(
googleAdvertisingId: value.googleAdvertisingId,
isLimitAdTrackingEnabled: value.isLimitAdTrackingEnabled);
}
}).catchError((error) {
print("error in refreshGoogleAdvertisingId. ${error}");
});
}
SDK 설정
SDK 초기화 시에 로그 활성화 등의 옵션을 설정할 수 있습니다.
로그 활성화 하기
플랫폼에 따라 DFConfig.iosLogEnable
혹은 DFConfig.androidLogEnable
를 사용합니다.
Map<String, dynamic> config = {
DFConfig.iosLogEnable: true,
DFConfig.androidLogEnable: true,
};
Dfinery.initWithConfig(serviceId: "YOUR_SERVICE_ID", config: config);
로그 레벨 변경하기
DFConfig.androidLogLevel
를 사용하여 Android 플랫폼의 로그 레벨 설정을 변경할 수 있습니다.
DFAndroidLogLevel
verbose :
2
debug :
3
info :
4
warn :
5
error :
6
assert :
7
Map<String, dynamic> config = {
DFConfig.androidLogLevel: DFAndroidLogLevel.verbose
};
Dfinery.initWithConfig(serviceId: "YOUR_SERVICE_ID", config: config);
완료
SDK 설치 및 초기화가 완료되었습니다.
Last updated