Import the Plugin
In your Dart code, import the Moca Flutter Plugin:
import 'package:moca_flutter/moca_flutter.dart';
Initialize the SDK
Initialize the SDK with your Moca credentials when your app starts:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Method: initializeSDK(String appKey, String appSecret)
// Use test credentials in non-production environments.
final result = await Moca.initializeSDK("your_app_key", "your_app_secret");
if (result.isSuccess) {
print("Moca SDK initialized successfully");
} else {
print("Error initializing Moca SDK: ${result.error}");
}
runApp(MyApp());
}
Moca credentials are available in the Moca Console. Please refer to this section for a step by step tutorial.
Identify the User
Set a stable unique identifier for the User to track user-specific events.
Future<MocaResult<void>> setUserId(String userId);
Set custom metadata for the User
To set an optional dictionary of custom metadata for the user, call:
Future<MocaResult<bool?>> setProperties(Map<String, dynamic> props);