2
0

docs: add extract cookie example

This commit is contained in:
Baptiste Arnaud
2022-07-26 08:02:27 +02:00
parent 22eb48be0b
commit 47d24c4447

View File

@ -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.