HƯỚNG DẪN SỬ DỤNG SDK ONETARGET FLUTTER
Link: https://pub.dev/packages/one_target_mobile_sdk
Import:
~Yaml: one_target_mobile_sdk: ^x.y.z (x.y.z là version)
~iOS: thêm đoạn code sau vào ios/Podfile
target 'OneTargetSample' do
use_frameworks!
pod 'OTMobileXCFramework'
end
target 'OnetargetNotificationServiceExtension' do
use_frameworks!
pod 'OTMobileXCFramework', "1.0.2"
end
Vd ở app Demo, toàn bộ Podfile được trình bày bên dưới:
platform :ios, '11.0'
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
pod 'OTMobileXCFramework'
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
target 'OnetargetNotificationServiceExtension' do
use_frameworks!
pod 'OTMobileXCFramework', "1.0.2"
end
~Android:
Thêm vào gradle (level project):
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Android manifest: thêm tag tools:replace="android:label" vào thẻ application.
Cách dùng:
1/ Khởi tạo các thông tin trước khi tracking:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
_setupTracking();
runApp(const MyApp());
}
void _setupTracking() {
G1SDK.setupSDK(
1,//môi trường sử dụng SDK [1: dev, 2: stg, 3: prod]
"Input your workspace id",
"Input your app push id",
isShowLog: false,
isEnableIAM: true,
)
.then((isSetupSuccess) {
Utils.log("_setupTracking isSetupSuccess $isSetupSuccess");
});
}
2/ Tiến hành tracking bằng phương thức:
void _trackEvent() {
var profile = <Map>[];
// profile.add({
// "name": "Loitp Flutter", // "email": "loitp@galaxy.one", // }); G1SDK.trackEvent(
{
"screen": "BookingSuccessScreen",
"phone": "123123123",
},
profile,
"purchase",
{
"ecommerce.currency": "VND",
"ecommerce.transaction_id": "33AJV3",
"ecommerce.value": "2899800",
"ecommerce.items.0.item_id": "VJ197",
"ecommerce.items.0.item_name": "Flight:SGN:HAN",
"ecommerce.items.0.item_category": "FareOption",
"ecommerce.items.0.item_variant": "Deluxe",
"ecommerce.items.0.flight_time": "05:15-07:25",
"ecommerce.items.0.flight_date": "2020-11-19",
"ecommerce.items.0.flight_from": "SGN",
"ecommerce.items.0.flight_to": "HAN",
"ecommerce.items.0.item_list_id": "Outbound:HAN:SGN",
"ecommerce.items.0.index": "1",
"ecommerce.items.0.quantity": "1",
"ecommerce.items.0.price": "899000",
"ecommerce.items.1.item_id": "VJ120",
"ecommerce.items.1.item_name": "Flight:HAN:SGN",
"ecommerce.items.1.item_category": "FareOption",
"ecommerce.items.1.item_variant": "SkyBoss",
"ecommerce.items.1.flight_time": "20:50-23:45",
"ecommerce.items.1.flight_date": "2020-11-27",
"ecommerce.items.1.flight_from": "HAN",
"ecommerce.items.1.flight_to": "SGN",
"ecommerce.items.1.item_list_id": "Outbound:HAN:SGN",
"ecommerce.items.1.index": "2",
"ecommerce.items.1.quantity": "1",
"ecommerce.items.1.price": "2000800",
// "ecommerce.items.2.item_id": "VJ120",
// "ecommerce.items.2.item_name": "Flight:HAN:SGN", // "ecommerce.items.2.item_category": "FareOption", // "ecommerce.items.2.item_variant": "SkyBoss", // "ecommerce.items.2.flight_time": "20:50-23:45", // "ecommerce.items.2.flight_date": "2020-11-27", // "ecommerce.items.2.flight_from": "HAN", // "ecommerce.items.2.flight_to": "SGN", // "ecommerce.items.2.item_list_id": "Outbound:HAN:SGN", // "ecommerce.items.2.index": "2", // "ecommerce.items.2.quantity": "1", // "ecommerce.items.2.price": "2000800" },
onResponse: (value) {
Utils.log(">>>onResponse $value");
},
onFailure: (value) {
Utils.log(">>>onFailure $value");
},
);
}
HƯỚNG DẪN CHẠY THỬ APP SAMPLE (OPTIONAL)
Sau khi check out xong source code của app sample, mở terminal và gõ các lệnh sau:
cd example
cd ios
flutter clean
flutter packages get
flutter run --verbose