| 1 |
/** |
| 2 |
* External dependencies |
| 3 |
*/ |
| 4 |
import Cookies from 'js-cookie'; |
| 5 |
|
| 6 |
const VISITOR_COOKIE_KEY_NAME = '_parsely_visitor'; |
| 7 |
|
| 8 |
export function getVisitorCookieRaw() { |
| 9 |
return Cookies.get( VISITOR_COOKIE_KEY_NAME ); |
| 10 |
} |
| 11 |
|
| 12 |
export function getVisitorCookie() { |
| 13 |
const cookieVal = getVisitorCookieRaw(); |
| 14 |
|
| 15 |
if ( ! cookieVal ) { |
| 16 |
return undefined; |
| 17 |
} |
| 18 |
|
| 19 |
const unescapedCookieVal = unescape( cookieVal ); |
| 20 |
|
| 21 |
try { |
| 22 |
return JSON.parse( unescapedCookieVal ); |
| 23 |
} catch ( e ) { |
| 24 |
return undefined; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
export function getUuidFromVisitorCookie() { |
| 29 |
return getVisitorCookie()?.id; |
| 30 |
} |
| 31 |
|