> For the complete documentation index, see [llms.txt](https://docs.chainvine.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chainvine.xyz/developers/use-cases/leverage-cookies.md).

# Leverage cookies

> Note: these operations rely on browser functionality and will throw an error if used in a non-browser context

### Storing a Referrer

```typescript
import { storeReferrer } from '@chainvine/sdk';

// Fetches the "r" query parameter from the URL (if available)
// and stores it in a CV_REF cookie with an expiration of 120 days
storeReferrer();
```

Should you already have a reference to he referrer's ID or if you would like to adjust the cookies expiration you may do so by providing overrides as below:

```typescript
storeReferrer({
  durationDays: 30, //Override the default cookie duration (120 days)
  referrer: 'ABC123', //Should you already have access to the referrer, and if you do not want it fetched from the URL, you can provide it directly
}); 
```

### Fetching a stored Referrer

Once you've stored the referrer, you can access it at any point in your application like so:

```typescript
import { getReferrer } from '@chainvine/sdk';

const referrer = getReferrer();
```

### Clearing the stored Referrer

The referrer cookie can be cleared at any point using the following operation:

```typescript
import { clearReferrer } from '@chainvine/sdk';

clearReferrer();
```


---

# 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://docs.chainvine.xyz/developers/use-cases/leverage-cookies.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.
