optimus_flutter 5.1.0 copy "optimus_flutter: ^5.1.0" to clipboard
optimus_flutter: ^5.1.0 copied to clipboard

Official Flutter plugin for the Optimus Platform, helping you accelerate workflows and maximize productivity.

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 ID

Use 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);