one_target_mobile_sdk 0.0.28 copy "one_target_mobile_sdk: ^0.0.28" to clipboard
one_target_mobile_sdk: ^0.0.28 copied to clipboard

G1 tracking's plugin

HƯỚNG DẪN SỬ DỤNG SDK ONETARGET FLUTTER

Link: https://pub.dev/packages/one_target_mobile_sdk

Yêu cầu:

[✓] Flutter (Channel stable, 3.3.7, on macOS 13.0 22A380 darwin-arm, locale en-VN)
    • Flutter version 3.3.7 on channel stable
    • Framework revision e99c9c7cd9, 2022-11-01 16:59:00 -0700
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Platform android-33, build-tools 33.0.0
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Build 14A400
    • CocoaPods version 1.11.3

Import SDK:

~Yaml: one_target_mobile_sdk: ^x.y.z (x.y.z là lasted version lấy từ link bên trên)

~iOS: thêm đoạn code sau vào ios/Podfile

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:

File gradle (level project):

buildscript {  
  ext.kotlin_version = '1.7.20'  
  repositories {  
      google()  
      mavenCentral()  
  }  
  
  dependencies {  
      classpath 'com.android.tools.build:gradle:7.3.1'  
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"  
  }  
}  
  
allprojects {  
  repositories {  
      google()  
      mavenCentral()  
      maven { url 'https://jitpack.io' }  
  }  
}

File gradle (level project):

compileSdkVersion 33
minSdk 21

Android manifest: thêm tag tools:replace="android:label" vào thẻ application. vd:

<application  
  android:name="${applicationName}"  
  android:icon="@mipmap/ic_launcher"  
  android:label="one_target_mobile_sdk_example"  
  tools:replace="android:label">

Cách dùng SDK:

Step 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.instance.setupSDK(  
      "[your_workspace_id]",
      "[your_app_push_id]",
      isShowLog: false,  
      isEnableIAM: true,
      )  
  .then((isSetupSuccess) {  
      print("_setupTracking isSetupSuccess $isSetupSuccess");  
  });  
}

trong đó: your_workspace_id: Workspace được tạo bởi portal OneTarget your_app_push_id: App Push ID ( Key push của phía bên OneTarget cung cấp )

Step 2/ Tiến hành tracking bằng phương thức:

void _trackEvent() {  
  var identify = {"ext_identify": "ext_identify_value"};  
  var profile = <Map>[];  
  profile.add({"ext_identify": "ext_identify_value"});  
  var eventName = "add_to_cart";  
  var eventData ={  
     "ecommerce.currency":"VND","ecommerce.trip_from":"HAN","ecommerce.trip_to":"SGN","ecommerce.trip_start_date":"2022-09-23","ecommerce.trip_return_date":"2022-09-23","ecommerce.trip_passengers":"1","ecommerce.trip_passengers_adult":"2","ecommerce.trip_passengers_children":"1","ecommerce.trip_passengers_infant":"0","ecommerce.trip_type":"roundTrip","ecommerce.items.0.item_id":"VJ197","ecommerce.items.0.item_name":"Flight:HAN:SGN","ecommerce.items.0.item_category":"FareOption","ecommerce.items.0.item_variant":"Eco","ecommerce.items.0.item_list_id":"Outbound:HAN:SGN","ecommerce.items.0.index":"1","ecommerce.items.0.quantity":"1","ecommerce.items.0.price":"39.000đ","ecommerce.items.0.flight_time":"06:20-08:30","ecommerce.items.0.flight_from":"HAN","ecommerce.items.0.flight_to":"SGN","ecommerce.items.0.flight_date":"2022-09-23","ecommerce.trip_route":"SGN-HN",  
  };  
  
  G1SDK.instance.trackEvent(  
      identify,  
      profile,  
      eventName,  
      eventData,  
  );  
}

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