blux_flutter 0.2.1
blux_flutter: ^0.2.1 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
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.
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"
)
);