UNPKG

@lukulent/svelte-umami

Version:

[![MadeWithSvelte.com shield](https://madewithsvelte.com/storage/repo-shields/5086-shield.svg)](https://madewithsvelte.com/p/svelte-umami/shield-link)

13 lines (12 loc) 698 B
import { writable } from 'svelte/store'; // Get the value out of storage on load. const stored = typeof localStorage !== 'undefined' ? localStorage.getItem('umami') : JSON.stringify({ enabled: true }); /** Svelte store to enable and disable the tracking. (https://umami.is/docs/track-events) */ export const isEnabled = writable(stored ? JSON.parse(stored).enabled : true); // Anytime the store changes, update the local storage value. isEnabled.subscribe((value) => typeof localStorage !== 'undefined' && localStorage.setItem('umami', JSON.stringify({ enabled: value }))); /** Svelte store to keep track of the status of the Umami script. */ export const status = writable(undefined);