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.

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 カテゴリは、アプリが分析イベントを送信することを認可するために、バックグラウンドで Authentication カテゴリを利用しています。

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: ^2.0.0
amplify_auth_cognito: ^2.0.0
amplify_flutter: ^2.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);
// ...
}

Analytics コンソールを表示

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

amplify console analytics

次のステップ:

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