> For the complete documentation index, see [llms.txt](https://docs.nosto.com/techdocs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nosto.com/techdocs/apis/frontend/implementation-guide-session-api/advanced-usage/spa-customizing-session-handling.md).

# Using external session identifiers

Nosto uses a cookie to identify browsers between their visits to the site. The purpose and usage of this cookie is very similar to how web analytics tools, such as Google Analytics, work.

Each session is identified using a randomly generated 24-character secure string and persisted in `2c.cId` cookie.

For privacy reasons, if you have the need to disallow any third-party tracking cookies, this feature can be used to achieve that.

{% hint style="info" %}
This feature will not remove previously set `2c.cId` cookies and will only affect sessions from the time of implementation onward.
{% endhint %}

## Changing the way sessions are handled

You can opt-out of tracking by using the `setCustomerIdentifierService` method.

Assuming that your platform has a method called `platform.getSID()` that returns the current session identifier as offered by your platform - you would use:

```javascript
nostojs((api) => {
  api.visit.setCustomerIdentifierService({
    getCustomerId: () => {
      return platform.getSID()
    },

    setCustomerId: id => {
      // Do nothing as you do not want to overwrite
      // the session identifier.
    }
  })
});
```

To showcase, the flexibility offered by this API - the following example simply uses `LocalStorage` (instead of cookies) to persist the session identifier.

```javascript
nostojs((api) => {
  api.visit.setCustomerIdentifierService({
    getCustomerId: () => {
      // Fetch the customer from to the LocalStorage
      // or return null if there is none i.e. a new
      // session
      return localStorage.getItem('my_nosto_id')
    },

    setCustomerId: id => {
      // Save the returned customer identifer to the
      // LocalStorage. 
      localStorage.setItem('my_nosto_id', id);
    }
  })
});
```

{% hint style="info" %}
To learn more about the `setCustomerIdentifierService` usage, please refer to the [official API documentation](https://nosto.github.io/nosto-js/interfaces/client.Visits.html#setcustomeridentifierservice-1)
{% 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://docs.nosto.com/techdocs/apis/frontend/implementation-guide-session-api/advanced-usage/spa-customizing-session-handling.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.
