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

イベントを記録する

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 Analyticsプラグインを使用すると、アプリ内でカスタムイベントを簡単に記録できます。プラグインはデバイスがネットワーク接続を失った場合の再試行ロジックを処理し、リクエストを自動的にバッチ処理してネットワーク帯域幅を削減します。

Future<void> recordCustomEvent() async {
final event = AnalyticsEvent('PasswordReset');
event.customProperties
..addStringProperty('Channel', 'SMS')
..addBoolProperty('Successful', true);
// 以下のようにプロパティを1つずつ追加することもできます
event.customProperties.addIntProperty('ProcessDuration', 792);
event.customProperties.addDoubleProperty('doubleKey', 120.3);
await Amplify.Analytics.recordEvent(event: event);
}

Amazon Pinpointのイベント数は、イベントを記録してから数分以内に更新されます。

ただし、フィルターセクションにイベントが表示されたり、カスタム属性がAmazon Pinpointに表示されたりするには、最大30分かかる場合があります。

イベントをフラッシュする

イベントはデフォルトで30秒ごとにネットワークにフラッシュされるように設定されています。これを変更したい場合は、amplify_outputs.dartを更新して、autoFlushEventsIntervalの値(ミリ秒単位)を設定してください。この設定により、イベントは10秒ごとにフラッシュされます:

{
"Version": "1.0",
"analytics": {
"plugins": {
"awsPinpointAnalyticsPlugin": {
"pinpointAnalytics": {
"appId": "<your-app-id>",
"region": "<your-app-region>"
},
"pinpointTargeting": {
"region": "<your-app-region>"
},
"autoFlushEventsInterval": 10
}
}
}
}

注意

autoFlushEventsIntervalを0に設定すると、イベントの自動フラッシュは無効化され、イベントの送信はあなたが責任を持つことになります。

イベントを手動でフラッシュするには、以下を呼び出します:

await Amplify.Analytics.flushEvents();

グローバルプロパティ

グローバルプロパティを登録して、Amplify.Analytics.recordEventのすべての呼び出しで送信できます。

Future<void> registerGlobalProperties() async {
final properties = CustomProperties()
..addStringProperty('AppStyle', 'DarkMode');
await Amplify.Analytics.registerGlobalProperties(
globalProperties: properties,
);
}

グローバルプロパティの登録を解除するには、Amplify.Analytics.unregisterGlobalProperties()を呼び出します:

Future<void> unregisterGlobalProperties() async {
await Amplify.Analytics.unregisterGlobalProperties(
propertyNames: ['AppStyle', 'OtherProperty'],
);
}

さらに、propertyNamesを指定しないでunregisterGlobalPropertiesを呼び出すことで、すべてのグローバルプロパティを削除できます:

Future<void> unregisterAllGlobalProperties() async {
await Amplify.Analytics.unregisterGlobalProperties();
}