Pass user data to the widget
Use `window.AskAnyDocsUser` before the widget script to attach user ID, email, name, and phone to widget conversations and escalation workflows.
When the AskAnyDocs widget runs inside a logged-in website or SaaS product, you can pass user identity to the widget before the first message is sent. This gives support and sales integrations enough context to act on escalations without asking the same user details again.
Basic setup
Define window.AskAnyDocsUser before the widget script.
<script>
window.AskAnyDocsUser = {
id: "user_123",
email: "customer@example.com",
name: "Customer Name",
phone: "+15551234567"
};
</script>
<script src="https://app.askanydocs.com/widget/BOT_ID.js" defer></script>
The object is read by the widget when it sends chat metadata. Put it before the embed script so the data is available from the first message.
Supported fields
| Field | Max length | Notes |
|---|---|---|
id |
128 | Your internal user, account, tenant, or customer ID |
email |
254 | Recommended for support tickets, CRM contacts, and notifications |
name |
255 | Display name for support teams |
phone |
32 | Optional phone number for follow-up |
Values can be strings or numbers. Empty values are ignored.
Automatically collected context
The widget also sends useful conversation context:
- current page URL
- referrer
- browser language and language list
- platform
- timezone
- screen and viewport dimensions
- page language from the HTML document
- user agent
- IP-derived country code when available
Page URL and referrer are also stored on message metadata, which helps you see where a user asked the question.
Why user data matters
User data improves escalation workflows:
- Webhooks can include the user object in the escalation payload.
- Helpdesk integrations can create tickets with the right requester email.
- CRM integrations can create or update HubSpot contacts or Pipedrive persons.
- Slack, Telegram, Discord, Microsoft Teams, and email notifications can include contact details.
- Live chat providers can identify the current visitor during handoff.
If no user email is available when escalation happens, the widget can ask the visitor for an email before dispatching the escalation.
Privacy and security notes
Only pass data that your team is allowed to process for support. Do not put access tokens, passwords, payment data, or private secrets into window.AskAnyDocsUser.
Because this object exists in browser JavaScript, treat it as visitor-visible data. Use your internal user ID only if it is acceptable for frontend code.
Related articles
Getting started
Start here if you are setting up AskAnyDocs for the first time. This guide explains the complete workflow: creating a bot, adding knowledge sources, checking indexing quality, configuring the widget, and preparing your assistant for a live website.
Create your first bot
The bot creation wizard guides you from basic company information to resources and preview settings. This article explains what each step does and how to make choices that improve answer quality.
Add website, documents, videos, and cloud sources
AskAnyDocs can index website pages, sitemap URLs, exact URL lists, uploaded files, YouTube transcripts, Google Drive files, Notion pages, and manual Q&A pairs. This guide explains when to use each source and which file formats are supported.