Skip to content

Cookies

Supersonic provides simple cookie helpers for setting and getting browser cookies.

Use setCookie() to store a value and getCookie() to read it later.

<script>
window.supersonic.init();
window.supersonic.utility.setCookie('visited', 'true', 30);
const visited = window.supersonic.utility.getCookie('visited');
console.log(visited);
</script>
window.supersonic.utility.setCookie('theme', 'dark', 7, {
path: '/',
sameSite: 'Lax',
secure: true
});
ArgumentTypeDescription
namestringThe cookie name to store.
valuestringThe cookie value to store.
daysnumberNumber of days before the cookie expires. Leave empty or 0 for a session cookie.
optionsobjectOptional settings such as path, sameSite, and secure.
const theme = window.supersonic.utility.getCookie('theme');
ArgumentTypeDescription
namestringThe cookie name to read from the browser.
  • The helper uses document.cookie under the hood.
  • The days argument controls the expiration time.
  • By default, cookies are created with the current path and a SameSite=Lax policy.
  • secure is enabled automatically when the page is served over HTTPS.