blux_flutter 0.2.5
blux_flutter: ^0.2.5 copied to clipboard
BluxClient Flutter SDK
Blux Flutter SDK Integration Guide #
Installation #
Using pub #
Add the Blux Flutter SDK to your project's pubspec.yaml file:
dependencies:
blux_flutter: ^0.2.0
Android setup #
The Flutter plugin depends on the Blux Android SDK, which is published through JitPack. Add JitPack to the repositories in your app's android/build.gradle or android/build.gradle.kts:
// build.gradle (Groovy), inside allprojects { repositories { ... } }
maven { url 'https://jitpack.io' }
// build.gradle.kts (Kotlin DSL), inside allprojects { repositories { ... } }
maven(url = "https://jitpack.io")
iOS setup #
iOS needs Xcode configuration on top of the Dart dependency: the push capability, an App Group, and a Notification Service Extension. Follow the Flutter integration guide.
Android built-in Kotlin (unreleased) #
The next release requires Flutter 3.44 or later and Dart 3.12 or later. On AGP 8, or on AGP 9 with android.builtInKotlin=false (the default in Flutter's templates), Flutter applies the Kotlin Gradle Plugin declared by your app to this plugin. With android.builtInKotlin=true, AGP's built-in Kotlin compiles it.
To enable built-in Kotlin in your app, use Flutter 3.47 or later and AGP 9 or later, migrate the app and its other Android plugins, and set android.builtInKotlin=true in android/gradle.properties. Keep android.newDsl=false for Flutter 3.47. After upgrading this package, run flutter pub get to update webview_flutter_android to 4.12.1 or later. See Flutter's app migration guide.
The bundled example builds with Flutter 3.47, AGP 9.1, and built-in Kotlin. It pins the flutter_inappwebview 6.2.0-beta.3 prerelease because the latest stable Android implementation does not support AGP 9. Its iOS deployment target is 15.0; the Blux plugin itself still supports iOS 13.0.
Upgrading from 0.1.x #
If your app links blux_flutter through Swift Package Manager — the default from Flutter 3.44 — and has a Notification Service Extension, remove pod 'BluxClient' from the extension target and link BluxClient through Swift Package Manager instead. Leaving the pod in place loads BluxClient twice. Apps on CocoaPods need no change. See the changelog.
Initialize #
To initialize the SDK, provide your Client ID and API Key:
import 'package:blux_flutter/blux_flutter.dart';
// somewhere in class
final bluxClient = BluxFlutter();
// ...
bluxClient.initialize(
bluxApplicationId: "BLUX_APPLICATION_ID",
bluxAPIKey: "BLUX_API_KEY",
requestPermissionsOnLaunch: true
);
// ...
getPushToken #
SDK 초기화 후 현재 푸시 토큰을 조회합니다. Android는 FCM 등록 토큰, iOS는 APNs 디바이스
토큰을 반환합니다. 토큰이 아직 준비되지 않았다면 null이고, Android의 FCM 등록 토큰 조회
실패는 PlatformException으로 전달됩니다. 푸시 토큰은 바뀔 수 있으며 알림 권한 상태와는
별개입니다.
final pushToken = await bluxClient.getPushToken();
iOS에서는 initialize() 완료가 APNs 등록을 기다리지 않습니다. 앱의
didRegisterForRemoteNotificationsWithDeviceToken 콜백을 연동 가이드대로
BluxAppDelegate.shared에 전달한 뒤 토큰을 조회하세요. requestPermissionsOnLaunch가
false이면 앱이 자체 권한 요청 흐름에서 registerForRemoteNotifications()도 직접 호출해야
합니다. APNs 콜백 전에는 null을 반환합니다.
User Management #
signIn #
Sign in a user by passing a unique user ID. Users with the same UserId are treated as the same user by the Blux service.
bluxClient.signIn(userId: 'USER_ID');
signOut #
Call this method when a user logs out of your service. It helps improve user identification accuracy.
bluxClient.signOut();
Sending Events #
Product Detail View Event #
Track when a user views a product detail page or expresses interest in an item.
bluxClient.sendEvent(
AddProductDetailViewEvent(
itemId: 'ITEM_ID',
)
);
Like Event #
Track when a user likes or favorites a product or video.
bluxClient.sendEvent(
AddLikeEvent(
itemId: 'ITEM_ID',
)
);
Add to Cart Event #
Track when a user adds a product to their shopping cart.
bluxClient.sendEvent(
AddCartaddEvent(
itemId: 'ITEM_ID',
)
);
Order Event #
Track when a user purchases a product. Provide the paidAmount as paid amount at the time of the transaction.
Single Product Order Example
BluxClient.sendEvent(
AddOrderEvent(
orderId: "ORDER_ID",
orderAmount: 200,
paidAmount: 100,
items: [
{
"id": "ITEM_ID",
"price": 200,
"quantity": 6
}
]
)
);
Multiple Products Order Example
BluxClient.sendEvent(
AddOrderEvent(
orderAmount: 200,
paidAmount: 100,
items: [
{
"id": "ITEM_ID_1",
"price": 200,
"quantity": 6
},
{
"id": "ITEM_ID_2",
"price": 300,
"quantity": 1
}
],
orderId: "ORDER_ID"
)
);