blux_flutter 0.2.0-rc.1
blux_flutter: ^0.2.0-rc.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_api_stage.dart';
import 'package:blux_flutter/blux_flutter.dart';
// somewhere in class
final bluxClient = BluxClient();
// ...
bluxClient.initialize(
bluxApplicationId: "BLUX_APPLICATION_ID",
bluxAPIKey: "BLUX_API_KEY",
requestPermissionsOnLaunch: true
);
// ...
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"
)
);