> 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?

You can integrate a custom toggle switch into your website to manage web push notifications easily (opt-in and opt-out).

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="https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2FJQw9OsQEpklNjTzOOOck%2Ftechnical-guides_toggle-deactive-notif_02052025.png?alt=media&amp;token=2a5a4a42-ed8c-458f-9266-7a38384cf880" 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="https://38998153-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCL8wF0y1T2vLnm3yR2MW%2Fuploads%2FopoZQsC479DKO4ELubN2%2Ftechnical-guides_toggle-button_02052025.gif?alt=media&amp;token=cec57332-a101-4ecb-9652-3bd1738c9508" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
