> For the complete documentation index, see [llms.txt](https://docs.edgetag.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.edgetag.io/implementation/server-side-cookie.md).

# Server-side cookie

A server-side cookie, or HTTP cookie, is sent from the server to the browser. You can read more about it in the [web documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). It’s important for the system to send data from the server because browsers can verify its origin and extend its validity. For platforms like Shopify, WordPress, and others, we’ve got you covered —we automatically generate this cookie for you, and it originates from the server where your site is served. However, for headless sites, we don’t have access to your server, so we recommend that you create it yourself. Our system will still generate a server-side cookie with the EdgeTag user ID, but it’s beneficial to have both the server-side cookie and ours running simultaneously. We will map your server-side cookie to ours behind the scenes.

### Cookie options

Important options:

* Name: cookie name. Make sure that you use a value that is not already used on your site or by any other provider that you have on your site.
* Domain: For which domain should the cookie be set? It's good to set it as .mysite.com so that it works with subdomains as well
* Expires - when the cookie should expire
* SameSite - in which context the cookie should live
* Secure - if the cookie should be only served on https
* HttpOnly - should the cookie be only available for requests

You can read more about it on the [web docs.](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie)

### How to create a cookie?

Server-side cookies should be included in the document response headers. This way, we know they came from the correct server.

{% hint style="warning" %}
A cookie should only be created if it doesn't exist yet.
{% endhint %}

Below is an example of how to create a server-side cookie on your end:

```javascript
const crypto = require('crypto');

const cookieName = 'truid'; // this is just an example name, you can change it to what you want
const userId = `${crypto.randomUUID()}-${Date.now()}`;
const expirationDate = new Date(2037, 11, 20).toUTCString();
const domainCookie = '.mysite.com'; // change mysite.com to your domain

const cookieString = `${cookieName}=${userId}; SameSite=LAX; Expires=${expirationDate}; Domain=${domainCookie}; HttpOnly; Secure`;

// add cookieString to your headers under key set-cookie
response.writeHead(200, {
    "Set-Cookie": cookieString
});

```


---

# 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.edgetag.io/implementation/server-side-cookie.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.
