Set Up User Context on Squarespace
Pass Member Areas user info to your chatbot
What You're Setting
User Context is a client-side JavaScript object. On every page where the widget loads for a logged-in user, you attach an object to window.Asyntai.userContext describing who they are. The widget sends this with each message, so the AI can reply with their name, order status, plan tier, or anything else relevant.
Keys act as labels the AI sees, so make them descriptive — use "Customer name" or "Loyalty points", not just "name" or "points".
window.Asyntai = window.Asyntai || {};
window.Asyntai.userContext = {
"Customer name": "Sarah Chen",
"Email": "sarah@example.com",
"Subscription plan": "Pro",
"Loyalty points": 1840,
"Last order": "#8847, out for delivery"
};
Two ways to set it
Either assign synchronously (if data is already on the page), or provide a fetcher that runs when the chat opens. The second option is better for performance — user data is only loaded when someone actually opens the chat.
// Option A — synchronous (data already available)
window.Asyntai.userContext = { "Customer name": "Sarah", ... };
// Option B — async fetch on chat open (better performance)
window.Asyntai.fetchUserContext = function() {
return fetch('/api/chat-context/')
.then(r => r.json())
.then(data => { window.Asyntai.userContext = data; });
};
Security & size: Never include passwords, credit card numbers, API tokens, or anything sensitive — this data is on the client and visible to anyone inspecting the page. Context is capped at 2,000 characters on Standard and 10,000 characters on Pro; if you exceed it, the tail is truncated.
How Squarespace Exposes the User
If you're using Squarespace Member Areas (available on Business+ plans), the logged-in member's basic info is exposed in the global Static.SQUARESPACE_CONTEXT.authenticatedAccount object on pages where the member is signed in. This includes email and display name.
Squarespace does not expose detailed member data (membership tier, subscription info) directly client-side — for richer fields, use Option 2 with the Member Accounts API and a proxy.
Option 1 — Code Injection (Member Areas only)
<script>
(function() {
var ctx = window.Static && Static.SQUARESPACE_CONTEXT;
var account = ctx && ctx.authenticatedAccount;
if (!account) return; // visitor not signed in
window.Asyntai = window.Asyntai || {};
window.Asyntai.userContext = {
"Name": account.displayName || '',
"Email": account.email || '',
"Account ID": account.id || ''
};
})();
</script>
Field availability: Squarespace's authenticatedAccount structure can vary between templates and member area configurations. Always test in a private browser window as a real signed-in member — if fields come back empty, open DevTools → Console and log window.Static.SQUARESPACE_CONTEXT to see what's actually there.
Option 2 — Proxy for Richer Data
For membership tier, subscription status, or commerce customer data, build a tiny external proxy that queries Squarespace's Member Accounts API or Commerce API (both require an OAuth-authenticated bearer token).
<script>
window.Asyntai = window.Asyntai || {};
window.Asyntai.fetchUserContext = function() {
var account = window.Static && Static.SQUARESPACE_CONTEXT
&& Static.SQUARESPACE_CONTEXT.authenticatedAccount;
if (!account) return Promise.resolve();
return fetch('https://your-proxy.example.com/user-context?account=' + account.id)
.then(r => r.json())
.then(data => { window.Asyntai.userContext = data; });
};
</script>
Your proxy calls the Squarespace Member Accounts API (GET /api/v1.0/members-accounts-api/profiles/{account_id}) with a stored bearer token, reshapes the response, and returns it.
Совет: If you aren't using Member Areas but have Commerce customers (people who've placed an order), you can look them up by email via the Squarespace Commerce API — handy for passing order context to repeat customers.
Устранение неполадок
Open your browser DevTools → Console → type window.Asyntai.userContext after the page loads. You should see your object. If it says undefined, your script didn't run — check the script order (context must be set after the widget script loads, or be re-set whenever the user logs in).
The widget reads window.Asyntai.userContext on every message. If a page loads fresh (no SPA routing), you need to set context on that page too. For single-page apps, set it once after login and update it whenever user data changes.
Re-assign window.Asyntai.userContext with the fresh data after any update. The next message the user sends will include the updated values — no page reload needed.
You're over the size limit (2k chars Standard, 10k Pro). Trim verbose fields — keep order history to last 2-3 items, truncate long descriptions, drop fields the AI doesn't need.
Visit the User Context settings page while logged in as a test user, then send a chat message. The status refreshes within a few seconds. If still empty, check the browser console for JavaScript errors and verify the object is set before the chat message is sent.
Privacy reminder: Only share fields relevant to the conversation. Passing a customer's full purchase history when they just want to ask a general question is wasteful and can confuse the AI. Scope context to what helps.