# SDK Opt-out

Opt-out is a feature that stops collecting a user's data. It is used to comply with privacy regulations or to respond to a user's request to stop data collection.

{% hint style="info" %}
Even in an opt-out state, SDK features such as A/B Tests, Feature Flags, and In-App Messages continue to work normally.
{% endhint %}

### How to Configure Opt-out

Opt-out can be configured in two ways:

* **Configure at initialization**: Set `optOutTracking` in the SDK initialization config.
* **Configure at runtime**: Change the opt-out state while the app is running using the `setOptOutTracking()` method.

### State Management

{% hint style="warning" %}
The SDK manages the opt-out state only in memory. When the app restarts, it resets to the value set in the initialization config.
{% endhint %}

The opt-out state changed via `setOptOutTracking()` is not persisted when the app restarts. When the app restarts, the `optOutTracking` value set in `HackleConfig` is applied.

#### Persistence Management

To persist a user's opt-out setting across app restarts, **you must manage it persistently in your app**.

**Recommended Implementation Flow**

1. When a user changes their opt-out setting, save the state to the app's persistent storage.
2. When the app starts, read the opt-out state from storage and set it in the SDK initialization config.
3. When the state changes while the app is running, update both the storage and the SDK.

**Persistent Storage Examples by Platform**

| Platform           | Persistent Storage                              |
| ------------------ | ----------------------------------------------- |
| iOS                | UserDefaults                                    |
| Android            | SharedPreferences                               |
| JavaScript / React | localStorage                                    |
| React Native       | AsyncStorage or MMKV                            |
| Flutter            | SharedPreferences (shared\_preferences package) |

{% hint style="info" %}
For specific usage of the opt-out API and code examples for persistence management, refer to each SDK's opt-out documentation.
{% endhint %}


---

# 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.hackle.io/en/development-guide/sdk/optout.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.
