Quay lại bảng điều khiển

Tài liệu

Tìm hiểu cách sử dụng Asyntai

Tính năng
Thanh Ask AI Thanh tìm kiếm AI Tìm kiếm AI cho WordPress AI Search for Joomla AI Search for Webflow AI Search for Ghost AI Search for Moodle AI Search for TYPO3 AI Search for Craft CMS AI Search for Grav AI Search for Concrete CMS AI Search for October CMS AI Search for ProcessWire AI Search for Odoo AI Search for Bagisto AI Search for Medusa AI Search for OpenCart AI Search for BigCommerce AI Search for Magento Thu thập dữ liệu Website Lỗ hổng tri thức Thẻ sản phẩm Thẻ sản phẩm động Hình ảnh động Ngữ cảnh Người dùng Công cụ tùy chỉnh Tham số liên kết Giám sát trực tiếp Tiếp quản bởi Con người Chuyển tiếp Thông báo AI Báo cáo Hàng ngày Nguồn Dữ liệu Thời gian thực Nguồn Dữ liệu Thời gian thực Tối đa Thành viên Nhóm Đăng nhập một lần Xác thực hai yếu tố Bao gồm Hình ảnh Nhận diện Hình ảnh Tiện ích Dịch thuật Bản địa hóa Tính minh bạch AI Khách hàng tiềm năng Thu thập Khách hàng Thông minh Phiếu Hỗ trợ Danh mục trò chuyện Đặt lịch Nhúng Loại trừ Trang IP bị chặn Chính sách lưu trữ Chế độ không lưu trữ Che dữ liệu cá nhân (PII) Bộ phân loại câu trả lời Access Tags Ghim phiên bản Widget Nhật ký kiểm toán Mô hình Thông minh hơn Bật Suy nghĩ Gợi ý Trả lời Tin nhắn Theo dõi Chuyển Giọng nói thành Văn bản Tải xuống Bản ghi Chat Nhúng Nhúng bằng iframe

Set Up User Context on Bubble

Pass Current User data to your chatbot using an HTML element

Back to User Context
Gói Standard, Pro và Enterprise

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": "[email protected]",
  "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 Bubble Works

Bubble's Current User is available in any HTML element via dynamic expressions. Drop an HTML element on a reusable header or the page, and use Bubble's dynamic text to inject the logged-in user's fields directly into a <script> block.

Option 1 — HTML Element with Dynamic Expressions (no plugins)

1
Add an HTML element to your Header reusable element Design tab → drag an HTML element onto your Header (or a page). Size it 1x1 — only the script matters, not the visible element.
2
Paste the template below into the element's HTML Click Insert dynamic data to replace the bracketed placeholders with real Bubble expressions like "Current User's Name".
3
Wrap it in a conditional Set the element's Conditional: when "Current User is logged in" → the element is visible. That way the script only renders for logged-in users.
<script>
  window.Asyntai = window.Asyntai || {};
  window.Asyntai.userContext = {
    "Name":  "[Current User's Name]",
    "Email": "[Current User's email]",
    "Plan":  "[Current User's Plan]",
    "Credits": [Current User's Credits]
  };
</script>

Bracketed placeholders become Bubble dynamic expressions. Wrap string fields in quotes; numeric fields can go unquoted.

Escape special characters: If a user's Name or email might contain a quote, ampersand, or angle bracket, Bubble's :formatted as JSON-safe modifier handles escaping for you. Or just avoid putting HTML-unsafe data in the fields at all.

Option 2 — Toolbox Plugin (cleanest)

The free Toolbox plugin adds a "Run JavaScript" action. On a page-load workflow, trigger Run JavaScript with a composed string — this gives you Bubble's full type system for data transforms (formatting dates, joining lists, etc.) before it hits the DOM.

// In a "Run JavaScript" action on page load,
// use Bubble dynamic data inside a workflow-composed script:
window.Asyntai = window.Asyntai || {};
window.Asyntai.userContext = {
  "Name":         "[Current User's Name]",
  "Email":        "[Current User's email]",
  "Member since": "[Current User's Created Date:formatted as 2021-01-01]"
};

Mẹo: Bubble SPAs don't reload between pages — which means the HTML element only runs its dynamic expressions when the reusable element first renders. Put it in your app's Header reusable so it's present on every page.

Khắc phục Sự cố

The AI doesn't seem to know who I am

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).

Context works on some pages but not others

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.

Data is stale after the user updates their profile

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.

Context is truncated

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.

User Context status page shows "Not receiving context"

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.