When you create a session you can pass user context. The assistant takes it into account for the whole conversation. Context may include:

  • user data (e.g. first name, id),
  • the current page or category,
  • preferences and interests,
  • browsing history,
  • any other fields.

Add a context field to the body of the request that creates the session:

const userContext = {
  user_id: "user_12345",
  first_name: "Alex",
  current_page: "Category: Sports",
  viewed_categories: ["footwear", "sport", "electronics"],
  preferences: { interests: ["running", "mountain biking"] }
};

const res = await fetch('https://widget-api.prosecaptain.com/api/v2/widget/thread', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN'
  },
  body: JSON.stringify({ widget_id: 'WIDGET_ID', context: userContext })
});
const { session_id } = await res.json();

When you resume an existing session (session_id) with a new context, the context is updated.

Page context

With every message you can send page_context, information about the page the user is on. The widget does this itself when Extract page context is on in the settings.

{
  "session_id": "session_xyz789",
  "message": "Does this model come in a women's version?",
  "page_context": {
    "url": "https://shop.com/shoes/run-pro",
    "title": "Run Pro running shoes",
    "content": "Page text, up to about 5000 characters…",
    "meta": { "description": "Lightweight road running shoes" }
  }
}

Data privacy

Do not send sensitive personal data such as full legal name, email, phone number or street address. Prefer identifiers, pseudonyms or partial data.