This is the official Amplitude Flutter SDK developed and maintained by Amplitude Inc.
iOS - 10 Android - API 21 (Lollipop)
Add the dependency to your project.
dependencies:
amplitude_flutter: ^2.0.0
Import the module and use its APIs.
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);
}
}
In iOS, to enable Advertising Id tracking, you will need to add AdSupport.framework
in your project setting page.
In Android, firstly you need to add com.google.android.gms:play-services-ads
as a dependency in your build.gradle
. If you use Google Mobile Ads SDK version 17.0.0 above. You need to add AD_MANAGER_APP
into your androidmanifest.xml
file.
Secondly, since we don't assume user's project will depend on this library, we use reflection to invoke its APIs. So the names of its classes can't be changed since reflection will use original name to find the class. You also need to add exception rules into your proguard-android.txt
or proguard-rules.pro
.
-keep class com.google.android.gms.ads.** { *; }
If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.