> For the complete documentation index, see [llms.txt](https://docs.nubrick.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nubrick.app/reference/flutter/nubrickdispatcher.md).

# NubrickDispatcher

### インターフェース

```dart
class NubrickDispatcher {
  Future<void> dispatch(NubrickEvent event)
}
```

### .dispatch <a href="#dispatch" id="dispatch"></a>

dispatch関数は、アプリ内のさまざまなイベントを定義するために使用できます。これにより、**イベントデータがNubrickサーバーに送信**され、Nubrickプラットフォームにおいて様々な用途で活用することができます。

この関数を使用することで、特定のエクスペリメントを表示させるトリガーを設定できたり、アプリ内でのユーザーのアクションやイベントをトラッキングし、アプリのパフォーマンスやユーザーの行動分析を行うことが可能になります。

{% hint style="success" %}
具体的なユースケース

* アプリ内でモーダルを表示させるトリガーとして使用。例えば、特定のボタンがクリックされた際や、特定のページを閲覧した際にモーダルを表示するなど。
* アプリ内でのKPIを評価するために使用。特定の機能がユーザーによってどれくらい利用されているかや、特定のUIをどれだけタップしているかを計測するなど。
  {% endhint %}

#### イベントを送信する際のコード例

```dart
import 'package:nubrick_flutter/dispatcher.dart';

await NubrickDispatcher().dispatch(NubrickEvent("<CUSTOM_EVENT_NAME>"))
```

### 詳細な使用例

#### アプリのXX機能を利用しているユーザーをトラッキング

```dart
import 'package:nubrick_flutter/dispatcher.dart';

Button(
  child: const Text('Press me!')
  onPressed: () {
    NubrickDispatcher().dispatch(NubrickEvent('PRESS_XX_FEATURE'))
  }
)
```

#### アプリ内でYYページを表示したときにXXイベントをトリガーまたは収集

```dart
import 'package:nubrick_flutter/dispatcher.dart';

class NubrickNavigatorObserver extends NavigatorObserver {
  @override
  void didPush(Route<dynamic> route, Route<dynamic>? result) {
    super.didPop(route, result);
    String name = route.settings.name ?? '';
    if (name.isNotEmpty) {
      NubrickDispatcher().dispatch(NubrickEvent('NAVIGATION_$name'));
    }
  }

  @override
  void didPop(Route<dynamic> route, Route<dynamic>? result) {
    super.didPop(route, result);
    String name = route.settings.name ?? '';
    if (name.isNotEmpty) {
      NubrickDispatcher().dispatch(NubrickEvent('NAVIGATION_$name'));
    }
  }
}

// ...
MaterialApp(
  routes: {
    // ...
  },
  navigatorObservers: [
    NubrickNavigatorObserver(),
  ],
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nubrick.app/reference/flutter/nubrickdispatcher.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
