# Callbacks

WProofreader provides callback functions for tracking events and integrating with your application logic. All callbacks are set in the configuration alongside other options.

| Callback                         | Triggered when                                                                                                                           |
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `onLoad`                         | WProofreader is loaded and ready to use.                                                                                                 |
| `onToggle`                       | WProofreader is enabled or disabled.                                                                                                     |
| `onCommitOptions`                | A user changes options like `lang`, `ignoreAllCapsWords`, `ignoreDomainNames`, `ignoreWordsWithMixedCases`, or `ignoreWordsWithNumbers`. |
| `onAddWordToUserDictionary`      | A word is added to the user dictionary.                                                                                                  |
| `onDeleteWordFromUserDictionary` | A word is deleted from the user dictionary.                                                                                              |
| `onCheckStatusChange`            | Text checking starts or finishes. Returns `'start'` or `'finish'`. Multiple cycles can occur due to asynchronous requests.               |
| `onStatistics`                   | A user interacts with a suggestion or dictionary (replace, ignore, add, delete, report, disable, accept, discard, mismatch, generate).   |
| `onUsage`                        | A check, autocorrect, autocomplete, or generate request is executed. Useful for monitoring usage and client-side analytics.              |
| `onErrorRequest`                 | A request ends with an error.                                                                                                            |

#### onStatistics

The `onStatistics` callback is triggered whenever a user interacts with a suggestion or dictionary. It captures the action type, input text, and metadata such as rule, language, and context.

**Actions:**

| Action     | Description                                                |
| ---------- | ---------------------------------------------------------- |
| `replace`  | User accepted a suggestion and replaced the original text. |
| `ignore`   | User ignored a suggestion.                                 |
| `add`      | Word was added to the user dictionary.                     |
| `delete`   | Word was removed from the user dictionary.                 |
| `report`   | User reported a suggestion as incorrect.                   |
| `disable`  | User disabled the rule behind a suggestion.                |
| `accept`   | User accepted an autocomplete suggestion.                  |
| `discard`  | Autocomplete suggestion was dismissed without interaction. |
| `mismatch` | Autocomplete suggestion didn't match user input.           |
| `generate` | User used a suggestion from the AI writing assistant.      |

**Suggestion types** returned in `data.type`: `spelling`, `grammar`, `style`, `autocomplete`, `autocorrect`.

For callback signatures and full parameter details, refer to the [Configuration reference](https://webspellchecker.com/docs/api/wscbundle/Options.html).


---

# Agent Instructions: 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:

```
GET https://docs.wproofreader.com/integrations/initialization/configuration-options/callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
