Show different Sanity content to returning visitors, how to do it
We use Sanity for our edtech site. I want a simple thing: first-time visitors see the explainer hero (what the product is), returning visitors see a sign-up push instead. Sanity has no idea if the visitor is new or returning, so where does that condition live?
We already mapped the hero to a Croct slot. I just dont know where to write the "is returning" logic, in my frontend code or somewhere in the dashboard.
1 answer
It lives in the dashboard, not in your code. When you create an experience you define who it targets, where it applies, and what content to serve. The "who" part is an audience written in CQL, and visitor state is a built-in signal, so your condition is literally:
user is returningCreate an experience for the hero slot, set that as the audience condition, and pick the sign-up push content as the variant. Audiences are evaluated in real time on each interaction, so the split happens on the very first pageview of a returning session, no code changes and nothing for Sanity to know about.
Your default Sanity hero (the explainer) stays as the fallback for anyone who does not match, which covers your first-time visitors automatically. You do not even need a second experience for them.
If you later want finer splits, there are related conditions like user is anonymous and user has signed up, so you could show the sign-up push only to returning visitors who have not created an account yet:
user is returning and not user has signed up