Optimus Flutter Plugin
Official Flutter plugin for the Optimus Platform, helping you accelerate workflows and maximize productivity.
Features
- Event Tracking
- Analytics
- FCM Token Utilities
SDK Initialization
Import the package and initialize Optimus:
import 'package:optimus_flutter/optimus_flutter.dart';
final Optimus optimus = Optimus(
appId: 'OPTIMUS_APP_ID',
appSecret: 'OPTIMUS_APP_SECRET',
apiEndpoint: 'OPTIMUS_API_ENDPOINT',
);
Usage
Initialize Optimus
import 'package:optimus_flutter/optimus_flutter.dart';
const Optimus optimus =Optimus(
appId: 'OPTIMUS_APP_ID',
appSecret: 'OPTIMUS_APP_SECRET',
apiEndpoint: 'OPTIMUS_API_ENDPOINT',
);
void initOptimus() async {
await optimus.ensureInitialized(
trackAppStatus: true, // for enable tracking app status like install, update, and open app automatically
);
}
Android ID Tracking Configuration
By default, the SDK uses the Firebase Installation ID (FID) as the device identifier.
If you want the SDK to use the Android ID (ANDROID_ID
), you can enable it explicitly:
optimus.enableAndroidIdTracking();
Important Notes
Make sure your app privacy policy and Google Play Data Safety disclosures reflect your use of device identifiers accurately.
Persistent identifiers, including Android IDUse for non-advertising purposes
You can use persistent identifiers as long as you have a privacy policy and handle the data in accordance with the Developer Distribution Agreement and all applicable privacy laws in the areas where you make your app available.
Set User Attributes
void setUserAttributes(){
optimus.setClientId("userId");
optimus.setAccount("username");
optimus.setFirstName("First Name");
optimus.setLastName("Last Name");
optimus.setEmail("email@address.id");
optimus.setMobile("08xxxxxxx");
optimus.setGender(OptimusGender.other | OptimusGender.male | OptimusGender.female);
optimus.setBirthday("01-01-2000");
}
Set user status
// login
optimus.login("userId");
// logout
optimus.logout();
Event Tracking
void trackOptimusEvent() {
final OptimusProperties optProperties = OptimusProperties()
..addAttribute('attrString', 'String')
..addAttribute('attrInt', 123)
..addAttribute('attrDouble', 1.23)
..addAttribute('attrBool', true)
..addAttribute('attrLocation', OptimusGeoLocation(-6.175392, 106.827153))
..addAttribute('attrList', ['LIST_1', 'LIST_2'])
..addISODateTime("attrDateTime", DateTime.now());
optimus.trackEvent("event_name", properties);
}
Push Notification Handling
// Track Push opt-in
optimus.setPushOptIn(optIn: true | false);
// register FCM token
optimus.handleFCMToken(token: "fcm_token");
// track push notification receive event
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
optimus.trackReceivePush(message.data);
});
@pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
if (Firebase.apps.isEmpty)
await Firebase.initializeApp();
if (message.data.isNotEmpty)
optimus.trackReceivePush(message.data);
}
// track Push notification click event
FirebaseMessaging.instance.getInitialMessage().then((initialMessage) {
if (initialMessage != null && isInitialMessageValid) {
optimus.trackClickedPush(initialMessage);
}
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
optimus.trackClickedPush(message);
});
SDK Logging & Debugging
// enable network log
optimus.enableSDKLogs();
// open Optimus network logging page
optimus.openOptimusLog(context);
Libraries
- client/client
- constants/constants
- dto/event/event
- dto/gender/gender
- dto/internal_session/internal_session
- dto/payload/notification_payload
- dto/request/invalidate_token_request
- dto/request/push_analytic_request
- dto/request/push_token_request
- dto/request/tracking_request
- dto/responses/response
- enums/optimus_enums
- exceptions/exceptions
- geo_location/geo_location
- optimus_flutter
- Dart library for the Optimus Flutter SDK.
- properties/properties
- utils/app_version_utils
- utils/campaign_utils
- utils/encyption_utils
- utils/fcm_token_utils
- utils/internal_session_utils