Cookies
Pass visitor data into your docs through a public or signed cookie.
Last updated
Was this helpful?
Pass visitor data into your docs through a public or signed cookie.
Last updated
Was this helpful?
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
JWT
Public cookie gitbook-visitor-public
Feature flags, roles
Easy to set up
JSON
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 object.
Below is a simple JavaScript example:
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:
Properties can only be defined by the backend
Visitor can override the properties
To pass data to GitBook more securely, you’ll need to send the data as a from your application in a cookie named gitbook-visitor-token
tied to your domain.