> For the complete documentation index, see [llms.txt](https://doc.batch.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.batch.com/developer/technical-guides/how-to-guides/web/how-to-allow-users-to-manage-their-push-preferences-from-my-website.md).

# How to allow users to manage their push preferences from my website?

By default, users can manage their push preferences from their browser settings on desktop and mobile ([see here how to disable push notifications](https://doc.batch.com/guides-and-best-practices/profiles/how-to-disable-web-push-notifications)).

Instead of making your users dive into their browser settings, you can give them the option to disable/enable push notifications directly from your website using a toggle switch.

<figure><img src="/files/BrN0AHDobqmT62XShh3T" alt="Example of a notifications switch button on a website" width="563"><figcaption></figcaption></figure>

The following steps will help you set up this button on your website.

{% stepper %}
{% step %}

## Getting users' opt-in status <a href="#id-1-getting-the-opt-in-status-of-the-user" id="id-1-getting-the-opt-in-status-of-the-user"></a>

First, you need to obtain the users' opt-in status to update the button's status.\
You can use this method :

```javascript
batchSDK(function (api) {api.isSubscribed()});
```

{% endstep %}

{% step %}

## Update the opt-in status <a href="#id-2-update-the-optin-status" id="id-2-update-the-optin-status"></a>

<figure><img src="/files/fldfUpjwYIxE2Uwcb1H7" alt="Gif showing a toogle button switching from off to on"><figcaption></figcaption></figure>

Depending on the action your users perform, you will need to call different methods when users click your toggle switch.

**Turning off** push notifications:

```javascript
batchSDK(function(api) {api.unsubscribe();});
```

**Turning on** push notifications:

```javascript
batchSDK(function(api) {api.subscribe();});
```

Here is an example of how you could implement a toggle switch using these methods:

```html
<input type="checkbox" id="toggle" onclick="validate();" />
```

```html
<script type="text/javascript">
      function validate() {
        if (document.getElementById("toggle").checked) {
          batchSDK(function(api) {api.subscribe();});
        } else {
          batchSDK(function(api) {api.unsubscribe();});
        }
      }
    </script>
```

{% endstep %}
{% endstepper %}

{% hint style="danger" %}
Keep in mind that notifications management may happen at two different levels:

* At the **SDK level**
* In users' **browser settings**: on this level, you cannot control notifications with a toggle switch button as described above.
  {% endhint %}

{% hint style="warning" %}
You will find more details in the [Batch Web API Reference](https://doc.batch.com/web-api-reference/).
{% endhint %}


---

# 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://doc.batch.com/developer/technical-guides/how-to-guides/web/how-to-allow-users-to-manage-their-push-preferences-from-my-website.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.
