Amplify Analytics をセットアップする
Analytics カテゴリでは、アプリ用の分析データを収集できます。Analytics カテゴリは Amazon Pinpoint と Amazon Kinesis(Kinesis サポートは現在のところ Amplify JavaScript ライブラリでのみ利用可能)の組み込みサポートで提供されています。Analytics カテゴリは Amazon Cognito Identity プールを使用してアプリ内のユーザーを識別します。Cognito により、アプリ内の認証済みユーザーと非認証ユーザーの両方からデータを受け取ることができます。
目的
Amplify Analytics でアプリケーションをセットアップおよび設定し、分析イベントを記録します。
前提条件
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 pushA configuration file called amplifyconfiguration.json will be copied to your configured source directory, for example ./src. The CLI will also print the URL for Amazon Pinpoint console to track your app events.
Amplify ライブラリをインストール
To install the Amplify library to use the analytics features, run the following command in your project’s root folder:
npm install aws-amplifyAmplify Analytics を初期化
Import and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example, App.js (Expo) or index.js (React Native CLI).
import { record } from 'aws-amplify/analytics';import amplifyconfig from './amplifyconfiguration.json';
Amplify.configure(amplifyconfig);User session data is automatically collected unless you disabled analytics. To see the results visit the Amazon Pinpoint console.
Analytics コンソールを表示
以前にリンクを保存していない場合でも、ターミナルからアクセスできます。コンソールを開くには、以下のコマンドを実行します。
amplify console analytics次のステップ:
おめでとうございます!Analytics のバックエンドをプロビジョニングし、Analytics ライブラリをインストールしました。Amplify Analytics のユースケースについては、以下のリンクをチェックしてください:
既知の問題
デフォルトの Pinpoint プロバイダーの代わりに、以下のリストされた代替サービスプロバイダーをインポートする場合:
- Kinesis (
aws-amplify/analytics/kinesis) - Kinesis Data Firehose (
aws-amplify/analytics/kinesis-firehose) - Personalize Event (
aws-amplify/analytics/personalize)
バンドラーを起動する際に、以下のエラーが発生する場合があります:
Error: Unable to resolve module stream from /path/to/node_modules/@aws-sdk/... これは既知の問題です。この問題で説明されている手順に従ってエラーを解決してください。