docs: add extract cookie example
This commit is contained in:
@ -50,3 +50,20 @@ window.location.href
|
||||
It will not give you the parent URL if you embed the bot on your site.
|
||||
A more bulletproof option is to pass the URL as a hidden variable in the embed code options. You can find an example [here](/embed/html-javascript#additional-configuration).
|
||||
:::
|
||||
|
||||
## Extract a cookie
|
||||
|
||||
This code allows you to extract the value of a cookie called "my_cookie":
|
||||
|
||||
```js
|
||||
const getCookie = (name) => {
|
||||
const value = `; ${document.cookie}`
|
||||
const parts = value.split(`; ${name}=`)
|
||||
if (parts.length === 2) return parts.pop().split(';').shift()
|
||||
return 'not found'
|
||||
}
|
||||
|
||||
return getCookie('my_cookie')
|
||||
```
|
||||
|
||||
As you can see the code can also be multi-line. The Set variable block will get the value following the `return` statement.
|
||||
|
Reference in New Issue
Block a user