Croct uses localStorage by default, how do I share identity across subdomains?
We run www.example.nl and shop.example.nl. Current behavior: a reader who crosses from www to shop shows up as a second anonymous profile, so their reading history does not follow them into the shop.
Desired behavior: one profile across both subdomains.
I understand the default storage is localStorage, which I actually like from a privacy standpoint, but localStorage is scoped per origin so I assume that is the cause here. What is the supported way to bridge subdomains, and what exactly do I need to configure
1 answer
localStorage is origin-scoped, exactly as you suspected, so www and shop each get their own client ID and Croct sees two anonymous profiles. The supported bridge is to switch identity storage to first-party cookies with a shared domain.
The plug call takes a cookie option where you configure this per cookie:
croct.plug({ appId: 'YOUR_APP_ID', cookie: { clientId: { name: 'croct.id', domain: 'example.nl', maxAge: 31536000, secure: true, }, userToken: { name: 'croct.user_token', domain: 'example.nl', secure: true, }, },});The two cookies that matter are croct.id (the client ID) and croct.user_token; a one-year maxAge is the typical choice for the client ID. Setting domain to the apex makes both subdomains read the same cookies, so the visitor is one profile everywhere. Each cookie also accepts path and sameSite if your setup needs them.
These are still first-party cookies on your own domain, so the privacy posture you like about the default does not really change, you are just widening the scope from one origin to your own site family.