Cookies
Pass visitor data into your docs through a public or signed cookie.
You can pass visitor data to your docs through your visitors browser cookies. Below is an overview of the different methods.
Signed cookie gitbook-visitor-token
API test credentials, customer identification
Require signing and a custom domain
✅ Properties can only be defined by the backend
JWT
Public cookie gitbook-visitor-public
Feature flags, roles
Easy to set up
❌ Visitor can override the properties
JSON
Public cookie
To pass data to GitBook from a public cookie, you’ll need to send the data from your application by setting a public gitbook-visitor-public
cookie.
Data passed through public cookies must be defined in your visitor schema through an unsigned object.
Below is a simple JavaScript example:
Signed cookie
To pass data to GitBook more securely, you’ll need to send the data as a JSON Web Token from your application in a cookie named gitbook-visitor-token
tied to your domain.
To set this up, you'll need to adjust your application’s login flow to include the following steps:
Generate a JWT when users logs in to your application
Whenever a user logs in to your product, generate a JWT that contains selected attributes of your authenticated user's info.
Sign the JWT using the site's visitor signing key
Then, make sure to sign the JWT using the site's visitor signing key, which you can find in your site’s audience settings after enabling Adaptive Content.
Store the JWT in a wildcard session cookie
Finally you need to store the signed JWT containing your user's info into a wildcard session cookie under your product domain.
For example, if your application is served behind the app.acme.org
domain, the cookie will need to be created under the .acme.org
wildcard domain.
Below is a simple TypeScript example:
Last updated
Was this helpful?