Installation
Install the Instalog Flutter SDK by adding it as a dependency in your project. You can find the package on pub.dev.
To include the SDK, add the following dependency to your pubspec.yaml
file:
dependencies:
instalog_flutter: ^0.1.1
Android
For feedback functionality on Android, ensure you have the Instalog activity registered in your AndroidManifest.xml:
<activity
android:name="dev.instalog.mobile.feedback.InstalogFeedbackActivity"
android:label="Instalog"
android:theme="@style/Theme.Instalog"/>
Usage
Initialization
Initialize the Instalog SDK at the start of your app:
import 'package:instalog_flutter/instalog_flutter.dart';
// Initialize in main.dart
void main() {
// Set up crash handling
Instalog.instance.crash.setup(
appRunner: () => runApp(const MyApp()),
);
}
// Initialize with your API key in a widget
@override
void initState() {
super.initState();
Instalog.instance.initialize(apiKey: 'your_api_key_here');
}
Configuration Options
Customize Instalog SDK behavior with InstalogOptions
:
import 'package:instalog_platform_interface/instalog_platform_interface.dart';
// Initialize with custom options
Instalog.instance.initialize(
apiKey: 'your_api_key_here',
options: const InstalogOptions(
isLogEnabled: true, // Enable event logging
isLoggerEnabled: false, // Disable internal debug logs
isCrashEnabled: true, // Enable crash reporting
isFeedbackEnabled: true // Enable feedback modal
),
);
All configuration options default to true
except for isLoggerEnabled
(defaults to false
).
Logging Events
Track custom events with optional parameters:
// Simple event
Instalog.instance.logEvent(event: 'button_clicked');
// Event with parameters
Instalog.instance.logEvent(
event: 'user_login',
params: {
'user_id': '12345',
'method': 'email',
'timestamp': DateTime.now().toIso8601String(),
},
);
Showing Feedback Modal
Display the in-app feedback modal to collect user input:
await Instalog.instance.showFeedbackModal();
Crash Reporting
Instalog automatically captures uncaught exceptions when set up with crash.setup()
. To manually report a caught exception:
try {
// Your code that might throw an exception
} catch (error, stack) {
Instalog.instance.sendCrash(error, stack);
}
User Identification
Associate events with a specific user:
// Identify user with a unique ID
Instalog.instance.identifyUser(userId: 'user_12345');
Identifying users allows you to track user-specific behavior and associate events and crashes with particular users, which is helpful for debugging and analytics.
Testing Crash Reporting
Simulate a crash to test your implementation:
// This will trigger a crash for testing purposes
Instalog.instance.crash.simulateCrash();
iOS
Ensure you have added the necessary permissions to your Info.plist
file if your app collects user data.
Android
If targeting Android 13 (API level 33) or higher, ensure you request the appropriate permissions for collecting user data.
Advanced Example
Here’s a complete example showing how to use multiple Instalog features together:
import 'package:flutter/material.dart';
import 'package:instalog_flutter/instalog_flutter.dart';
import 'package:instalog_platform_interface/instalog_platform_interface.dart';
void main() {
// Set up crash handling
Instalog.instance.crash.setup(
appRunner: () => runApp(const MyApp()),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
// Initialize with options
Instalog.instance.initialize(
apiKey: 'your_api_key_here',
options: const InstalogOptions(
isLogEnabled: true,
isLoggerEnabled: false,
isCrashEnabled: true,
isFeedbackEnabled: true,
),
);
// Identify the user
Instalog.instance.identifyUser(userId: 'user_${DateTime.now().millisecondsSinceEpoch}');
// Log app start event
Instalog.instance.logEvent(
event: 'app_started',
params: {
'timestamp': DateTime.now().toIso8601String(),
'version': '1.0.0',
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Instalog Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => Instalog.instance.showFeedbackModal(),
child: const Text('Show Feedback Modal'),
),
ElevatedButton(
onPressed: () {
try {
// Simulate an error
throw Exception('Test exception');
} catch (error, stack) {
Instalog.instance.sendCrash(error, stack);
}
},
child: const Text('Simulate & Report Error'),
),
],
),
),
);
}
}
Troubleshooting
Common Issues
-
SDK Not Initialized
- Ensure
initialize()
is called before using other SDK methods
- Verify your API key is correct
-
Missing Crash Reports
- Check that crash reporting is enabled in your configuration
- Verify your app has network permissions
-
Events Not Being Logged
- Check network connectivity
- Ensure the SDK is properly initialized
For additional support, contact [email protected]