Need to configure your backend?See Build a Backend →
イベントを記録する
イベントを記録する
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);}イベントをフラッシュする
イベントはデフォルトで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();}