Skip to content

PersistedStore

PersistedStore is a thin static wrapper around window.localStorage for persisting data across page reloads.

View as Markdown llms.txt
import { PersistedStore } from '@segmentify/integration';
PersistedStore.setItem('myKey', 'myValue');
const value = PersistedStore.getItem('myKey'); // 'myValue'
PersistedStore.removeItem('myKey');
PersistedStore.clear();

Since localStorage only stores strings, serialize objects:

PersistedStore.setItem('user', JSON.stringify({ email: 'user@example.com' }));
const parsed = JSON.parse(PersistedStore.getItem('user') || 'null');

The library uses PersistedStore for data that must survive page reloads:

KeyPurpose
__store:__segmentifyEventQueue__Events deferred with nextPage: true
sgfUserUpdateDataCached user identification data

::: warning Avoid overwriting these keys — the library depends on them. :::

For how ReactiveStore and PersistedStore compare, see the comparison table in ReactiveStore.