data-persist. The script creates a random id, keeps it in the browser’s localStorage under crispstats_vid, and sends it with every event. It is off by default, because it stores an identifier on the visitor’s device.
Without it, CrispStats recognises a visitor for one day only, from a daily-rotating hash, and stores nothing in the browser.
Turn on persistent visitors
The setting and the attribute work together: the collector uses the id only while the setting is on, and the script creates an id only when the tag hasdata-persist. The dashboard keeps the two in step, so follow these steps in order.
1
Turn on the site setting
In the dashboard, open Settings, General, Persistent visitors and turn on Recognise returning visitors across days. Changing site settings needs the owner or admin role on the site.
2
Deploy the updated snippet
Open Settings, Tracking code. The snippet for your platform now includes If you write the tag by hand, add
data-persist, and the note under it says so. Copy it and replace the tag on your site:data-persist (data-persist="" in JSX) only while the setting is on.3
Check that the id is stored
Open your site, then run this in the browser console:It returns a string of digits. Visit the site again on a later day from the same browser and the visitor is counted as returning.
How it works
1
The script creates an id
On the first page load with
data-persist, the script generates an id from 128 random bits with crypto.getRandomValues and saves it in localStorage.crispstats_vid. Later page loads reuse it. The id is random: it is not derived from the device, the IP address or the User-Agent.2
Every event carries it
The script sends the id as
vid with each event. crispstats.id() also passes it to the collector, so the visitor id you send to your payment provider at checkout matches the stored one.3
The collector hashes it per site
When the site setting is on, the collector stores the first 32 hex characters of
SHA-256("persist" | site id | id) as the visitor id. It has the same shape as a daily id, and the same browser gets a different value on each of your sites, so stored ids cannot be matched across sites. The raw id from localStorage is not stored. No salt rotation applies, so the id stays the same across days.localStorage, the event falls back to the daily hash. The IP address and User-Agent are still read for the browser, device, location and bot filtering, and discarded as usual.
What changes in your reports
- Visitors over a period count each id once. Without persistent visitors, a visitor on three different days counts as three. See counting visitors.
- Retention cohorts count returns on later days for persistent visitors, not only for visitors you identify.
- Visitor profiles gather a browser’s visits from every day under one profile, with the source and landing page of its first visit.
Consent considerations
The script readsdata-persist once, when it starts, and a second copy of the script on the same page is ignored. To load it only after consent, inject the tag from your consent tool’s callback:
loadCrispStats(true) once the visitor has given consent, and loadCrispStats(false) otherwise. Call it once per page load, after your consent tool knows the visitor’s choice. If the script already started without data-persist on this page, the id is created from the next page load that includes the attribute.
When a visitor withdraws consent
Stop addingdata-persist for that visitor, and delete the stored id:
Turning the setting off
When you turn Persistent visitors off, the collector stops usingvid within about a minute, once its cached copy of your site settings refreshes, and uses the daily hash for new events. Ids already in visitors’ browsers stay there until they are cleared, and the script keeps sending them for as long as data-persist is on your tag. Remove the attribute as well if you no longer want them sent.
Learn more on crispstats.com
- Glossary: unique visitor, visitor hash, retention and cookie consent.
Next steps
Cookieless tracking
How the default daily id is built and why it cannot be linked across days.
Compliance facts
What each option changes, summarised for a privacy review.
Retention cohorts
See how often visitors come back on later days.