Flutter is an open-source UI Software Development Kit created by Google. It is used to develop applications for Android, iOS, Windows, Mac, Linux, Google Fuchsia and the Web.
Installation
1. Add dependency
- Go to the
pubspec.yaml
file and add Amplitude SDK as a dependency.
dependencies:
amplitude_flutter: ^2.0.0
- Run
flutter pub get
in the terminal to install the SDK.
2. Track advertising ID (Optional)
Please refer to this.
3. iOS Installation
- Add
platform :ios, '10.0'
to your Podfile. - If you want to enable Bitcode, please follow the Flutter's documentation.
Quick Start
import 'package:amplitude_flutter/amplitude.dart';
import 'package:amplitude_flutter/identify.dart';
class YourClass {
Future<void> exampleForAmplitude() async {
// Create the instance
final Amplitude analytics = Amplitude.getInstance(instanceName: "project");
// Initialize SDK
analytics.init(widget.apiKey);
// Enable COPPA privacy guard. This is useful when you choose not to report sensitive user information.
analytics.enableCoppaControl();
// Set user Id
analytics.setUserId("test_user");
// Turn on automatic session events
analytics.trackingSessionEvents(true);
// Log an event
analytics.logEvent('MyApp startup', eventProperties: {
'friend_num': 10,
'is_heavy_user': true
});
// Identify
final Identify identify1 = Identify()
..set('identify_test',
'identify sent at ${DateTime.now().millisecondsSinceEpoch}')
..add('identify_count', 1);
analytics.identify(identify1);
// Set group
analytics.setGroup('orgId', 15);
// Group identify
final Identify identify2 = Identify()
..set('identify_count', 1);
analytics.groupIdentify('orgId', '15', identify2);
}
}
Usage & Examples
Please see the SDK Usage & Examples page.
FAQ
Errors on turning on Bitcode in iOS?
Please follow the Flutter's documentation
Need Help?
If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.
Updated 3 months ago