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