amplitude_flutter 1.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 95

amplitude_flutter #

pub package

The Official Amplitude Flutter plugin. Used to track events with Amplitude.

Getting Started #

To use this plugin, add amplitude_flutter as a dependency in your pubspec.yaml file.

Find the API key for your Amplitude project under your project settings.

Import package:amplitude_flutter/amplitude_flutter.dart, and instantiate AmplitudeFlutter with your API key.

In the example below - replace the string API_KEY with your API Key.

In addition, a Config object can be passed as a constructor argument for additional options. NOTE: This plugin's methods should only be called from the main isolate.

Advertising Id Tracking #

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 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

-keep class** { *; }

Adding Carrier Information #

You can set an option in the config object titled getCarrierInfo to retreive carrier name for a device. This is the ( Config). This object can be passed as a constructor argument for additional options.

If you set getCarrierInfo to true - recipients on Android devices will see a dialog box asking them for perimssion . This dialog will say allow app to make and manage phone calls. This is a message sent from the android operating system for the READ_PHONE_STATE permission and carrier info is grouped into this. If the user denies permission - carrier information will not be retrieved. The new android operating systems require asking a user for permission before retrieving this information.

By default the Config will set getCarrierInfo will default to false.

And example can be found here Example.

Example #

import 'package:amplitude_flutter/amplitude_flutter.dart';

// replace 'API_KEY' with your project's API_KEY
Future<void> example() async {
  final AmplitudeFlutter analytics = AmplitudeFlutter('API KEY');

  // set this user's id

  // log an event
  analytics.logEvent(name: 'add_friend');

  // Log events with event properties
  analytics.logEvent(name: 'add_friend', properties: { 'event_properties': { 'key': 'value' }});

  // identify a user
  final Identify identify = Identify()
    ..set('cohort', 'Test A')
    ..setOnce('completed_onboarding', 'true')
    ..add('login_count', 1)
    ..append('tags', 'new tag')


  // Amplitude Accounts [] methods:
  // add a user to a group
  analytics.setGroup('orgId', 15);

  // change properties of a group
  analytics.groupIdentify('orgId', 15, Identify()..set('account_manager', 456));

  // emit an event associated with a group
  analytics.logEvent('Demo Released', properties: { 'groups': { 'orgId': 15 } });

  // Log revenue
  final Revenue revenue = Revenue()


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.

1.3.0 #

  • Give user the abilities to customize the DB store. Thanks @reinaldomoreira!

1.2.1 #

  • Fix a problem that device type shows empty value for iOS devices.

1.2.0 #

  • Can track advertising Id now.
  • Will use a random UUID for device Id if ads tracking is disabled on the phone.
  • Device Id will be persisted locally to keep consistency.
  • Fixed wrong value population for os related properties in an event.

1.1.5 #

  • Include language property when reporting events.

1.1.4 #

  • Updated to use androidx for Android.

1.1.3 #

  • Fix a problem that dart documentation can't be generated on

1.1.2 #

  • Made changes to support the new Android plugins API (>= 1.12 Flutter SDK).
  • Updated Android example application with v2 Android embedding.

1.1.1 #

  • Migrated from AppLifecycleState.suspending to AppLifecycleState.detached. Cause suspending is deprecated. Thanks @otopba for fixing it.
  • Fixed the possible crash while other permission is requested by other libraries.

1.1.0 #

  • add device_manufacturer info
  • add ability to retrieve carrier info
  • add config option to turn on and off retrieving carrier info

1.0.1 #

  • Wait for device info to be available before sending events

1.0.0 #

  • Send event_id with payloads
  • Add application version to events
  • Limit stored events

0.2.0 #

  • Add setUserId()
  • Add a sequence_id sent with events
  • Config option to opt out of tracking
  • Example app changes

0.1.0 #

  • Adds revenue tracking.
  • Catch errors from platform channels.

0.0.2 #

  • Fixes bug where default session timeout was not set.
  • Persist events to sqlite database.
  • Refactor to use service provider class to simplify dependency injection in test.
  • Add group identify functionality.
  • Retry posting events.
  • Flush event buffer every 30s.
  • Retry posting events when payload is too large.
  • Include uuid for events.
  • Include library version for events.

0.0.1+1 #

  • Fixes serialization bug preventing events from sending.

0.0.1 #

  • Implements logEvent and identify functionality.


import 'package:flutter/material.dart';

import 'my_app.dart';

void main() => runApp(const MyApp('a79cefed0b7076cf3998ef7578a18bf0'));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  amplitude_flutter: ^1.3.0

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:amplitude_flutter/amplitude_flutter.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/src/metadata_store.dart. (-0.50 points)

Analysis of lib/src/metadata_store.dart reported 1 hint:

line 6 col 21: Use ; instead of {} for empty constructor bodies.

Format lib/src/amplitude_flutter.dart.

Run flutter format to format lib/src/amplitude_flutter.dart.

Format lib/src/constants.dart.

Run flutter format to format lib/src/constants.dart.

Format lib/src/device_info.dart.

Run flutter format to format lib/src/device_info.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
crypto ^2.0.6 2.1.4
device_info ^0.4.1+4 0.4.2+1
flutter 0.0.0
http ^0.12.0+2 0.12.0+4
package_info >=0.4.0+13 <2.0.0 0.4.0+16
path ^1.6.4 1.6.4
shared_preferences ^0.5.6+2 0.5.6+3
sqflite ^1.1.5 1.3.0
uuid ^2.0.1 2.0.4
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
convert 2.1.1
flutter_web_plugins 0.0.0
http_parser 3.1.4
meta 1.1.8
pedantic 1.9.0
shared_preferences_macos 0.0.1+6
shared_preferences_platform_interface 1.0.3
shared_preferences_web 0.1.2+4
sky_engine 0.0.99
source_span 1.7.0
sqflite_common 1.0.0+1
string_scanner 1.0.5
synchronized 2.2.0
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
mockito 4.0.0