Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Apr 30, 2024

Maintenance ModeYou are viewing Amplify Gen 1 documentation. Amplify Gen 1 has entered maintenance mode and will reach end of life on May 1, 2027. New project should use Amplify Gen 2. For existing Gen 1 projects, a migration guide and tooling are available to help you upgrade. Switch to the latest Gen 2 docs →

Amplify Analyticsのセットアップ

AWS will end support for Amazon Pinpoint on October 30, 2026,, and is no longer accepting any new users as of May 20 (see the linked doc). The guidance is to use AWS End User Messaging for push notifications and SMS, Amazon Simple Email Service for sending emails, Amazon Connect for campaigns, journeys, endpoints, and engagement analytics. Pinpoint recommends Amazon Kinesis for event collection and mobile analytics.

Amplify Flutter v1 is deprecated as of April 30th, 2025. No new features or bug fixes will be added. Dependencies may become outdated and potentially introduce compatibility issues.

Please use the latest version (v2) of Amplify Flutter to get started.

If you are currently using v1, follow these instructions to upgrade to v2.

Analytics カテゴリを使用すると、アプリのアナリティクスデータを収集できます。Analytics カテゴリは Amazon PinpointAmazon Kinesis に組み込みサポートを備えています (Kinesis サポートは現在 Amplify JavaScript ライブラリでのみ利用可能です)。Analytics カテゴリは Amazon Cognito Identity プールを使用してアプリのユーザーを識別します。Cognito を使用すると、アプリの認証済みユーザーと認証されていないユーザーからデータを受け取ることができます。

目標

Amplify Analytics を使用してアプリケーションをセットアップおよび設定し、アナリティクスイベントを記録します。

前提条件

Amplify Flutter requires a minimum target platform for iOS (13.0), Android (API level 24), and macOS (10.15). Additional setup is required for some target platforms. Please see the platform setup guide for more details on platform specific setup.

Analytics バックエンドのセットアップ

プロジェクトのルートフォルダで以下のコマンドを実行します。CLI は Analytics カテゴリの設定オプション (Amazon Pinpoint リソース名やアナリティクスイベント設定など) をプロンプトします。

Analytics カテゴリは、アプリがアナリティクスイベントを送信することを許可するために、バックグラウンドで認証カテゴリを使用します。

amplify add analytics
? Select an Analytics provider (Use arrow keys)
`Amazon Pinpoint`
? Provide your pinpoint resource name:
`yourPinpointResourceName`
? Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send analytics events? (we recommend you allow this when getting started)
`Yes`

バックエンドをデプロイするには、以下を実行します。

amplify push

Upon completion, you can see the result as the following that is going to be providing you a link to reach your analytics data:

✔ All resources are updated in the cloud
Pinpoint URL to track events https://<YOUR-PROJECT-RELATED-URL>/analytics/overview

In addition, amplifyconfiguration.dart will be updated to reference provisioned backend analytics resources. Note that these files should already be a part of your project if you followed the Project setup walkthrough.

Amplify ライブラリをインストール

In your Flutter project directory, open pubspec.yaml.

You will already have configured Amplify by following the steps in the project setup.

Add Analytics by adding these libraries into your dependencies block:

dependencies:
amplify_analytics_pinpoint: ^1.0.0
amplify_auth_cognito: ^1.0.0
amplify_flutter: ^1.0.0

Amplify Analytics を初期化

Add the Auth and Analytics plugin, along with any other plugins you may have added as described in the Project Setup section;

import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
Future<void> _configureAmplify() async {
// Add Pinpoint and Cognito Plugins, and any other plugins you want to use
final analyticsPlugin = AmplifyAnalyticsPinpoint();
final authPlugin = AmplifyAuthCognito();
await Amplify.addPlugins([analyticsPlugin, authPlugin]);
}

When running your app on macOS you will need to enable keychain sharing in Xcode, as described in the Project setup guide.

Make sure that the amplifyconfiguration.dart file generated in the project setup is included and sent to Amplify.configure:

import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
Future<void> _configureAmplify() async {
// ...
await Amplify.addPlugins([analyticsPlugin, authPlugin]);
// Once Plugins are added, configure Amplify
// Note: Amplify can only be configured once.
try {
await Amplify.configure(amplifyconfig);
} on AmplifyAlreadyConfiguredException {
safePrint(
'Tried to reconfigure Amplify; this can occur when your app restarts on Android.',
);
}
}

Your class will look like this:

import 'package:amplify_flutter/amplify_flutter.dart';
import 'package:amplify_analytics_pinpoint/amplify_analytics_pinpoint.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
Future<void> _configureAmplify() async {
// Add any Amplify plugins you want to use
final analyticsPlugin = AmplifyAnalyticsPinpoint();
final authPlugin = AmplifyAuthCognito();
await Amplify.addPlugins([analyticsPlugin, authPlugin]);
// Once Plugins are added, configure Amplify
// Note: Amplify can only be configured once.
try {
await Amplify.configure(amplifyconfig);
} on AmplifyAlreadyConfiguredException {
safePrint(
'Tried to reconfigure Amplify; this can occur when your app restarts on Android.',
);
}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await _configureAmplify();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}): super(key: key);
// ...
}

アナリティクスコンソールを表示

以前のリンクを保存していない場合でも、ターミナルから到達できます。以下のコマンドを実行してコンソールを開きます。

amplify console analytics

次のステップ:

おめでとうございます! Analytics バックエンドをプロビジョニングし、Analytics ライブラリをインストールしました。Amplify Analytics のユースケースについては、以下のリンクをご覧ください。